struts2访问web元素

来源:互联网 发布:lol for mac 国服下载 编辑:程序博客网 时间:2024/05/22 03:18

可以用#加上key值来访问Stack context中的值.如下所示:

     login succeed!
    <s:property value="#request.r1"></s:property>
    <s:property value="#session.s1"></s:property>
    <s:property value="#application.a1"></s:property><br/>
    username is:<s:property value="#parameters.username"></s:property><br/>
    password is:<s:property value="#parameters.password"></s:property>
    <s:debug></s:debug>//用此标签,页面上会有一个debug链接,点击此链接,可以看到后台传递的一些值.
 
 <s:form name="f" method="post">
 <s:textfield name="username" label="用户名"></s:textfield>
 <s:password name="password" label="密码"></s:password>
 <tr>
 <td><input type="button" value="submit1" onclick="javascript:document.f.action='login/login1';document.f.submit();"/></td>
 
 <td><input type="button" value="submit2" onclick="javascript:document.f.action='login/login2';document.f.submit();"/></td>
 
   </tr>
   <tr>
   <td><input type="button" value="submit3" onclick="javascript:document.f.action='login/login3';document.f.submit();"/></td>
  <td><input type="button" value="submit4" onclick="javascript:document.f.action='login/login4';document.f.submit();"/></td>
  </tr>
 </s:form>
struts.xml配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<package name="com.action" namespace="/" extends="struts-default">
<action name="user" class="com.action.UserAction">
<result name="success">/success.jsp</result>
<result name="error">/loginFailed.jsp</result>
</action>
</package>
</struts>
原创粉丝点击