• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is more of a struts question, but what do you have in your struts config file?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to the Struts forum.
bear
 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
reply
    Bookmark Topic Watch Topic
  • New Topic