File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The page will go to main.jsp even user don't input username?

 
Yashnoo lyo
Ranch Hand
Posts: 152
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I write a registe jsp page. If the user don't input name the error message will output and go to the registe page.But the jsp page go to main.jsp even I don't input username. My code is:
/////////////////////////////////////RegisteAction.java//////////////////////////////////////
public class RegisteAction extends Action{
ActionMessages errors=new ActionMessages();
PrintWriter out=null;
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception{
MessageResources resources=getResources(request);
HttpSession session=request.getSession();

Userinfo user=null;
user=(Userinfo)request.getAttribute("user");
System.out.println("before regform..."); //debug
Registeform regform=(Registeform)form;
System.out.println("After regform..."); //debug
String lyo=regform.getAction();
try{
if(!lyo.equals("create")){
if(user==null){
return mapping.findForward("signin");
}else{
this.updateuser(regform,mapping);//If user change their password , then update database
PropertyUtils.copyProperties(user,regform);
session.setAttribute("user",user);
return mapping.findForward("success");
}
}
System.out.println("lyo=="+lyo);
if(lyo.equals("create"))
System.out.println(errors.toString());
System.out.println("After try your name is:"+regform.getName());
if(regform.getName()==null)
errors.add("username",new ActionMessage("error.username.required"));
System.out.println("Your name is:"+regform.getName()); //debug
if((regform.getAddselect())==null)
errors.add("address",new ActionMessage("error.address.required"));
if((regform.getMenselect())==null)
errors.add("age",new ActionMessage("error.age.required"));
if((regform.getPassword1())==null||(regform.getPassword2())==null)
errors.add("password",new ActionMessage("error.password.required"));
if(!(regform.getPassword1()).equals(regform.getPassword2()))
errors.add("password2",new ActionMessage("error.password.match"));
System.out.println("Password1:"+regform.getPassword1()+"Password2:"+regform.getPassword2());


}catch(Exception eo){
System.out.println(eo.toString());
}
if(!errors.isEmpty()){
this.saveErrors(request,errors);
return mapping.findForward("registe"); //remain in this page
}

session.setAttribute("user",user);
return mapping.findForward("success"); //go to main.jsp

}
The console output is "lyo=create.Your name is:"
Why the user can go to main.jsp? :roll:
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33674
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is more of a struts question, but what do you have in your struts config file?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Struts forum.
bear
 
Yashnoo lyo
Ranch Hand
Posts: 152
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my struts-config.xml is:
<form-beans>
<form-bean name="actionform" type="lyo.hotmail.bbs.loginform"/>
<form-bean name="registeform" type="lyo.hotmail.bbs.Registeform" />
</form-beans>
<global-forwards>
<forward name="signin" path="/signin.do"/>
<forward name="signout" path="/signout.do"/>
<forward name="registe" path="/registe.do?lyo=create"/>

<forward name="success" path="/jsp/main.jsp"/>
</global-forwards>
<action-mappings>
<action path="/signin" type="org.apache.struts.actions.ForwardAction" parameter="/jsp/login.jsp"/>
<action path="/login" type="lyo.hotmail.bbs.loginaction" name="actionform"/>
<action path="/registe" type="org.apache.struts.actions.ForwardAction" parameter="/jsp/registe.jsp"/>
<action path="/saveRegiste" type="lyo.hotmail.bbs.RegisteAction" name="registeform" scope="request" validate="true" input="registe" >
<forward name="registe" path="/jsp/registe.jsp"/>
<forward name="success" path="/jsp/main.jsp"/>
</action>
</action-mappings>
It is right? :roll:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic