struts2 form表单按钮不跳转
如图,填好了form表单的数据以后按按钮发现没有跳转。PS:struts.xml的配置<struts><packagename="default"namespace="/...
如图,填好了form表单的数据以后按按钮发现没有跳转。
PS:struts.xml的配置
<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="login" class="WebDemo.LogInAction" method="execute">
<result name="OK">/Success.jsp</result>
<result name="Fail">/Fail.jsp</result>
</action>
</package>
</struts>
jsp里form表单代码:
<form action="login" method="post">
用户名:<input type="text" name="username"/><br/>
密码: <input type="password" name="password"/><br/>
<input type="submit" value="提交">
</form>
action的代码:
public class LogInAction {
private String username;
private String password;
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 execute()
{ System.out.println(this.username+this.password);
if(this.username.equals("obw")&&this.password.equals("123456"))
{
//System.out.println(this.username+this.password);
return "OK";
}
else
return "Fail";
}
} 展开
PS:struts.xml的配置
<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="login" class="WebDemo.LogInAction" method="execute">
<result name="OK">/Success.jsp</result>
<result name="Fail">/Fail.jsp</result>
</action>
</package>
</struts>
jsp里form表单代码:
<form action="login" method="post">
用户名:<input type="text" name="username"/><br/>
密码: <input type="password" name="password"/><br/>
<input type="submit" value="提交">
</form>
action的代码:
public class LogInAction {
private String username;
private String password;
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 execute()
{ System.out.println(this.username+this.password);
if(this.username.equals("obw")&&this.password.equals("123456"))
{
//System.out.println(this.username+this.password);
return "OK";
}
else
return "Fail";
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询