读书人

开始学习Struts遇到一个有关问题,请

发布时间: 2012-01-30 21:15:58 作者: rapoo

开始学习Struts,遇到一个问题,请大家帮助。
刚刚开始学习Struts,遇到一个问题,index.jsp点击提交按钮的时候地址栏里显示
http://localhost:8080/mystruts/register.do;jsessionid=3FA77C83EA8BCCCECCF2B522E1A30EB8
画面并没有任何显示信息,也就是说没有转到success.jsp或者failure.jsp,请问错误是出在什么地方?
struts-config.xml配置的 <form-beans> 和 <action-mappings> 信息如下:
//-------------------------start----------------------------------
<form-beans>
<form-bean
name= "RegisterForm "
type= "actionform.RegisterForm ">
</form-bean>
</form-beans>
<action-mappings>
<action
path= "/register "
type= "action.RegisterAction "
name= "RegisterForm "
scope= "request "
input= "/index.jsp ">
<forward
name= "success "
path= "/success.jsp "/>
<forward
name= "failure "
path= "/failure.jsp "/>
</action>
</action-mappings>
//------------------------end--------------------------------------

RegisterAction.java文件内容:
//------------------------start--------------------------------------
package action;

import java.io.IOException;
import javax.servlet.http.*;
import actionform.RegisterForm;
import org.apache.struts.action.*;
import javax.servlet.ServletException;

public class RegisterAction extends Action {

public ActionForward excute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest req,
HttpServletResponse res) throws IOException, ServletException {

RegisterForm rf = (RegisterForm) form;
String username = rf.getUsername();
String password = rf.getPassword();
String repassword = rf.getRepassword();

if (isNullOrEmpty(username)) {
return mapping.findForward( "failure ");
}

if (isNullOrEmpty(password)) {
return mapping.findForward( "failure ");
}

if(isNullOrEmpty(repassword)){
return mapping.findForward( "failure ");
}

return mapping.findForward( "success ");
}

private boolean isNullOrEmpty(String string){

return string == null || string.trim().length() == 0;

}
}
//------------------------end---------------------------------------
RegisterForm.java文件内容:
//----------------------------start-------------------------------
package actionform;

import javax.servlet.http.*;
import org.apache.struts.action.ActionForm;

public class RegisterForm extends ActionForm {

private String username;
private String password;
private String repassword;

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 getRepassword() {
return repassword;
}

public void setRepassword(String repassword) {
this.repassword = repassword;
}
}
//------------------------end-------------------------------------

[解决办法]
jsessionid是正常的,是Tomcat识别Session用的一个方法而已。
你需要打一下log或者debug,首先看程序有没有执行你的Action
[解决办法]
if (isNullOrEmpty(username)) {
return mapping.findForward( "failure ");
}

if (isNullOrEmpty(password)) {
return mapping.findForward( "failure ");
}

if(isNullOrEmpty(repassword)){
return mapping.findForward( "failure ");
}

return mapping.findForward( "success ");
}

private boolean isNullOrEmpty(String string){

return string == null || string.trim().length() == 0;

读书人网 >Java Web开发

热点推荐