struts 1 - hibernate strut1 action is not executing -
the action register.jsp not executing though described in struts-config.xml. have login.jsp page working well. register.jsp not throwing error doesnt execute. please take @ code. thanks
register.jsp
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%> <%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <title>insert title here</title> </head> <body> <h1>register</h1> <html:form action="register"> <bean:message key="label.username" /> <html:text property="username"></html:text> <html:errors property="username" /> <br/> <bean:message key="label.name"/> <html:text property="name"></html:text> <html:errors property="name"/> <br/> <bean:message key="label.mobile"/> <html:text property="phone_number"></html:text> <html:errors property="phone_number"/> <br/> <html:submit/> <html:reset/> </html:form> <% if(request.getattribute("msg1")!=null){ %> <%= request.getattribute("msg1") %> <%} request.setattribute("msg1","null"); %> <% if(request.getattribute("msg2")!=null){ %> <%= request.getattribute("msg2") %> <%} request.setattribute("msg2","null"); %> <% if(request.getattribute("msg3")!=null){ %> <%= request.getattribute("msg3") %> <%} request.setattribute("msg3","null"); %> </body> </html> **registeraction** public class registeraction extends action { @suppresswarnings({ "rawtypes", "unused" }) public actionforward execute(actionmapping mapping, actionform form, httpservletrequest request, httpservletresponse response) throws exception { session session = hibernateutil.getsessionfactory().opensession(); transaction trans = null; loginform loginform = (loginform) form; string email = loginform.getusername(); string name = loginform.getname(); int mobile = loginform.getphone_number(); boolean new_user = true; loginform lform = null; string result = "success"; try{ trans = session.begintransaction(); list ulogin = session.createquery("from loginform").list(); (iterator iterator = ulogin.iterator(); iterator.hasnext();){ lform = (loginform) iterator.next(); if (lform.getusername().equals(email) && lform.getphone_number()==mobile){ result = "failure"; break; } if(lform.getusername().equals(email)){ result = "failure1"; break; } if(lform.getphone_number() == mobile){ result = "failure2"; break; } } if(result.equals("failure")){ request.setattribute("msg3", "email , mobile number exist"); } if(result.equals("failure1")){ request.setattribute("msg1", "email exist"); } if(result.equals("failure2")){ request.setattribute("msg2", "mobile number exist"); } if(result.equals("success")){ string password = long.tohexstring(double.doubletolongbits(math.random())); lform = new loginform(); lform.setname(name); lform.setphone_number(mobile); lform.setusername(email); lform.setpassword(password); lform.setnew_user(new_user); session.save(lform); sendemail sendemail = new sendemail(); request.setattribute("msg4", "registered successfully"); } } catch (hibernateexception e){ if (trans!=null) trans.rollback(); e.printstacktrace(); } return mapping.findforward(result); } }
struts-config.xml
<?xml version="1.0" encoding="utf-8"?> <!doctype struts-config public "-//apache software foundation//dtd struts configuration 1.2//en" "http://struts.apache.org/dtds/struts-config_1_3.dtd"> <struts-config> <form-beans> <form-bean name="loginform" type="com.company.strutsuser.loginform" /> </form-beans> <global-exceptions> </global-exceptions> <global-forwards></global-forwards> <action-mappings> <action path="/login" name="loginform" validate="true" input="/login.jsp" type="com.company.strutsuser.loginaction"> <forward name="success" path="/success.jsp" /> <forward name="failure" path="/login.jsp" /> <forward name="failure1" path="/changepassword.jsp" /> <forward name="failure2" path="/login.jsp" /> </action> <action path ="/register" name="loginform" validate="true" input="/register.jsp" type="com.company.strutsuser.registeraction"> <forward name="success" path="/login.jsp" /> <forward name="failure" path="/register.jsp" /> <forward name="failure1" path="/register.jsp" /> <forward name="failure2" path="/register.jsp" /> </action> </action-mappings> <message-resources parameter="resource.messageresource"></message-resources> </struts-config>
loginform(my bean class)
import javax.servlet.http.httpservletrequest; import org.apache.struts.action.actionerrors; import org.apache.struts.action.actionform; import org.apache.struts.action.actionmapping; import org.apache.struts.action.actionmessage; @suppresswarnings("serial") public class loginform extends actionform{ private string username; private string password; public actionerrors validate(actionmapping mapping, httpservletrequest request) { actionerrors actionerrors = new actionerrors(); if(username == null || username.trim().equals("")) { actionerrors.add("username", new actionmessage("error.username")); } try { if(password == null || password.trim().equals("")) { actionerrors.add("password", new actionmessage("error.password")); } if(name == null || name.trim().equals("")) { actionerrors.add("name", new actionmessage("error.name")); } if(phone_number == 0) { actionerrors.add("phone_number", new actionmessage("error.mobile")); } }catch(exception e) { e.printstacktrace(); } return actionerrors ; } 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 getname() { return name; } public void setname(string name) { this.name = name; } public int getphone_number() { return phone_number; } private string name; private int phone_number; public void setphone_number(int phone_number) { this.phone_number = phone_number; } public boolean isnew_user() { return new_user; } public void setnew_user(boolean new_user) { this.new_user = new_user; } boolean new_user; private int id; public int getid() { return id; } public void setid(int id) { this.id = id; } }
console
aug 07, 2013 3:38:58 pm org.apache.catalina.core.aprlifecyclelistener init info: apr based apache tomcat native library allows optimal performance in production environments not found on java.library.path: c:\program files\java\jre7\bin;c:\windows\sun\java\bin;c:\windows\system32;c:\windows;c:\program files\common files\microsoft shared\windows live;c:\program files (x86)\common files\microsoft shared\windows live;c:\windows\system32;c:\windows;c:\windows\system32\wbem;c:\windows\system32\windowspowershell\v1.0\;c:\program files (x86)\windows live\shared;. aug 07, 2013 3:38:58 pm org.apache.tomcat.util.digester.setpropertiesrule begin warning: [setpropertiesrule]{server/service/engine/host/context} setting property 'source' 'org.eclipse.jst.jee.server:strutsuser' did not find matching property. aug 07, 2013 3:38:58 pm org.apache.coyote.http11.http11protocol init info: initializing coyote http/1.1 on http-8080 aug 07, 2013 3:38:58 pm org.apache.catalina.startup.catalina load info: initialization processed in 801 ms aug 07, 2013 3:38:58 pm org.apache.catalina.core.standardservice start info: starting service catalina aug 07, 2013 3:38:58 pm org.apache.catalina.core.standardengine start info: starting servlet engine: apache tomcat/6.0.37 aug 07, 2013 3:38:59 pm org.apache.struts.action.actionservlet initchain info: loading chain catalog jar:file:/c:/users/edith/documents/java/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/strutsuser/web-inf/lib/struts-core-1.3.10.jar!/org/apache/struts/chain/chain-config.xml aug 07, 2013 3:39:00 pm org.apache.coyote.http11.http11protocol start info: starting coyote http/1.1 on http-8080 aug 07, 2013 3:39:00 pm org.apache.jk.common.channelsocket init info: jk: ajp13 listening on /0.0.0.0:8009 aug 07, 2013 3:39:00 pm org.apache.jk.server.jkmain start info: jk running id=0 time=0/52 config=null aug 07, 2013 3:39:00 pm org.apache.catalina.startup.catalina start info: server startup in 1982 ms aug 07, 2013 3:39:01 pm org.apache.struts.util.propertymessageresources loadlocale warning: resource resource/messageresource_en_us.properties not found. aug 07, 2013 3:39:01 pm org.apache.struts.util.propertymessageresources loadlocale warning: resource resource/messageresource_en.properties not found. aug 07, 2013 3:39:07 pm org.apache.struts.chain.composablerequestprocessor init info: initializing composable request processor module prefix ''
Comments
Post a Comment