struts2采用域模型方式接收参数,出现user对象为空?! 如果将属性放入action中,并生成set get方法,可以
struts.xml:<struts><constantname="struts.i18n.encoding"value="gbk"/><constantname="st...
struts.xml:
<struts>
<constant name="struts.i18n.encoding" value="gbk" />
<constant name="struts.devMode" value="true" />
<package name="user" namespace="/user" extends="struts-default">
<action name="user" class="com.sd.action.TestAction">
<result>
/rec.jsp
</result>
</action>
</package>
</struts>
-----------------------------------------
index.jsp:
<form action="user/user!rec" method="post">
姓名:<input type="text" name="username"><br/>
密码:<input type="password" name="password"><br/>
<input type="submit" value="提交"/>
</form>
--------------------------
Action:
public class TestAction extends ActionSupport {
private User user;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String rec() {
if(user != null) {
System.out.println("username=" + user.getUsername());
System.out.println("password=" + user.getPassword());
} else {
System.out.println(user);
}
return SUCCESS;
}
-----------------------------------
User类我就不写了,两个属性+get set方法! 展开
<struts>
<constant name="struts.i18n.encoding" value="gbk" />
<constant name="struts.devMode" value="true" />
<package name="user" namespace="/user" extends="struts-default">
<action name="user" class="com.sd.action.TestAction">
<result>
/rec.jsp
</result>
</action>
</package>
</struts>
-----------------------------------------
index.jsp:
<form action="user/user!rec" method="post">
姓名:<input type="text" name="username"><br/>
密码:<input type="password" name="password"><br/>
<input type="submit" value="提交"/>
</form>
--------------------------
Action:
public class TestAction extends ActionSupport {
private User user;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String rec() {
if(user != null) {
System.out.println("username=" + user.getUsername());
System.out.println("password=" + user.getPassword());
} else {
System.out.println(user);
}
return SUCCESS;
}
-----------------------------------
User类我就不写了,两个属性+get set方法! 展开
1个回答
Storm代理
2023-08-29 广告
2023-08-29 广告
"StormProxies是全球大数据IP资源服务商,其住宅代理网络由真实的家庭住宅IP组成,可为企业或个人提供满足各种场景的代理产品。点击免费测试(注册即送1G流量)StormProxies有哪些优势?1、IP+端口提取形式,不限带宽,I...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询