zoukankan      html  css  js  c++  java
  • jsp js action之间传值

    1、struts2 action如何向JSP的JS函数传值

    action中定义变量

    public class TestAction extends ActionSupport implements ServletRequestAware {
        private String state = "test";
    }


    JSP的JS函数中引用变量

    <script type=text/javascript>
        function getStatus() {
            var t = "${state}";
            alert(t);
        }
    </script>



    2、struts2 action如何向JSP传值

    action中定义变量

    public class TestAction extends ActionSupport implements ServletRequestAware {
        private String state = "test";
    }



    JSP中引用变量

    <s:property value="#port.publicPort" />



    3、JSP如何向struts2 action的函数传值

    JSP中的值在form中通过submit的方式提交到action中,如下:

    <form class="form-horizontal">
        <input type="text" name="state" id="state" onclick="doTest()"></input>
    </form>
    <script type=text/javascript>
        function doTest() {
            document.forms[0].method = "post";
            document.forms[0].action="<%=request.getContextPath()%>/TestManage_showTest";
            document.forms[0].submit();    
        }
    </script>



    action中获取此值

    public String showTest() throws Exception {
        String state = (String)httpServletRequest.getParameter("state");
    }



    4、JSP如何向JS传值

    JSP中定义的变量

    <input type="text" name="state" id="state" value="test"></input>



    JS中可以使用下面的方法引用变量的值

    <script type=text/javascript>
    var v = document.getElementById("state").value;
    </script>


    5、JSP定义和使用java变量

    JSP中定义的java变量

    <%
    String userId = "test";
    %>


    JSP中可以使用下面的方法引用此变量

    '<%=userId%>'
  • 相关阅读:
    算法笔记 #003# 堆排序
    算法导论(第三版)练习 6.2-1 ~ 6.2-6
    Python开发【第六篇】:模块
    Python开发【第五篇】:Python基础之杂货铺
    Python开发【第四篇】:Python基础之函数
    Python开发【第三篇】:Python基本数据类型
    Python开发【第二篇】:初识Python
    python mysql
    跟着ttlsa一起学zabbix监控呗
    zabbix进程构成
  • 原文地址:https://www.cnblogs.com/wowind/p/6852708.html
Copyright © 2011-2022 走看看