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%>'

  • 相关阅读:
    归并两路有序链表
    [转]两种高性能I/O设计模式(Reactor/Proactor)的比较
    linux 静态库使用经验
    系统性能调优经验
    编译-O 选项对性能提升作用
    [转]Linux shell中的那些小把戏
    shell函数传递带空格的参数
    标题清洗引发的算法(两个字符串的最长公共子串)
    正则表达式之Matcher类中group方法
    ConcurrentHashMap JDK 1.6 源码分析
  • 原文地址:https://www.cnblogs.com/zzyrunning/p/4561059.html
Copyright © 2011-2022 走看看