您的位置:首页 > 编程语言 > Java开发

struts2访问web元素

2011-02-24 10:16 411 查看
可以用#加上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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: