- 爱易网页
-
Java教程
- struts.xml的配置有关问题,请高手指教
日期:2014-05-19 浏览次数:20703 次
struts.xml的配置问题,请高手指教
我在学习struts2,练习其中的重定向的一个的小例子,其中有action1.jsp负责表单的内容,提交到Action1的action类,有一个待转发到的Action2类,有一个处理结果的actin2.jsp,action1.jsp的代码如下:
<body>
<form action="action1.action">
username:<input type="text" name="username" /><br/>
password:<input type="password" name="password" /><br/>
<input type="submit" value="submit"/>
</form>
</body>
Action1的代码如下:
public class Action1 extends ActionSupport
{
private String username;
private String password;
private String usernameAndpassword;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsernameAndpassword() {
return usernameAndpassword;
}
public void setUsernameAndpassword(String usernameAndpassword) {
this.usernameAndpassword = usernameAndpassword;
}
@Override
public String execute() throws Exception {
this.usernameAndpassword = this.username+ this.password;
return SUCCESS;
}
}
Action2的代码如下:
public class Action2 extends ActionSupport
{
private String username;
private String password;
private String usernameAndpassword;
public String execute()throws Exception
{
return SUCCESS;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsernameAndpassword() {
return usernameAndpassword;
}
public void setUsernameAndpassword(String usernameAndpassword) {
this.usernameAndpassword = usernameAndpassword;
}
}
action2.jsp的代码如下:
<body>
username:<s:property value="username"/><br/>
password:<s:property value="password"/><br/>
usernameAndpassword:<s:property value="usernameAndpassword"/><br/>
</body>
问题是我在struts.xml中的配置是这样的
<action name="action1" class="com.shengsiyuan.struts2.Action1">
<result name="success" type="redirectAction">
<param name="actionName">action2</param>
<param name="username">${username}</param>
<param name="password">${password}</param>
<param name="usernameAndpassword" >${usernameAndpassword}</param>
</result>
</action>
但是struts.xml中总是报错,错误提示是undefined actionnamespace parameter,请高手指教,我那里错了
------解决方案--------------------
<result name="success" type="redirectAction">
action2?username=${username}&&password=${password}
</result>
------解决方案--------------------
加上个<param name="namespace">/</param>