aspose file tools*
The moose likes Struts and the fly likes The page will go to main.jsp even user don't input username? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "The page will go to main.jsp even user don Watch "The page will go to main.jsp even user don New topic
Author

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

Yashnoo lyo
Ranch Hand

Joined: Feb 17, 2003
Posts: 152
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:


When I face C# and Java I choose Java.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30948
    
158

This is more of a struts question, but what do you have in your struts config file?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61656
    
  67

Moving to the Struts forum.
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Yashnoo lyo
Ranch Hand

Joined: Feb 17, 2003
Posts: 152
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:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The page will go to main.jsp even user don't input username?