This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes nothing is happening in action class when i submit a page(struts ) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "nothing is happening in action class when i submit a page(struts )" Watch "nothing is happening in action class when i submit a page(struts )" New topic
Author

nothing is happening in action class when i submit a page(struts )

arulraj michealraj
Greenhorn

Joined: Mar 02, 2005
Posts: 28
I am learning struts. I did one sample struts program. i have one problem that nothing is happening in action class when i submit a page. i don't know what is happenging there. I have configured xml files correctly.
The following files are being used:
struts-config.xml
******************
<form-beans>
<form-bean name="LoginForm" type="com.atroad.form.LoginForm"/>
</form-beans>
<action-mappings>
<action path="/LoginAction"
name="LoginForm"
type="com.atroad.action.LoginAction"
scope="request">
<forward name="success" path="com/atroad/ui/success.jsp"/>
</action>
</action-mappings>
web.xml
**********
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
Action class
***************



package com.atroad.action;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class LoginAction extends Action
{
public ActionForward execute(HttpServletRequest request,HttpServletResponse response,ActionMapping mapping,ActionForm form)throws Exception
{
System.out.println("111dfss11111111111");
//String username=request.getParameter("username");
//String password=request.getParameter("password");
return mapping.findForward("success");
}

}


form
*********
package com.atroad.form;
import org.apache.struts.action.*;

public class LoginForm extends ActionForm
{
String username=null;
String password=null;
public void setUsername(String username)
{
this.username=username;
}
public void setPassword(String password)
{
this.password=password;
}
public String getPassword()
{
return this.password;
}
public String getUsername()
{
return this.username;
}
}



Note:

In action class, i have given a s.o.p to ensure whether control is coming inside or not.


Can you please give any suggestion?
Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213
Hello ,

Your struts-config.xml , web.xml , Action and ActionForm code seems to be ok.. The only difference which i am seeing here is in the signature of the ActionForward , You have written like this :

public ActionForward execute(HttpServletRequest request,HttpServletResponse response,ActionMapping mapping,ActionForm form)throws Exception ---> The use of direct Exception class should be avoided.

while normally which i have seen is like this :

public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException. I dont know if changing the signature would work , but you may try. Anywayz , Lets wait for the experts opinion, Merrill , please come at the rescue. :-)

Can you let us know the exact error which you are coming across , perhaps the Stack trace would suffice..

You say "Nothing is Happening there", Where are you submitting form from ? which is the page which actually is sending control to /LoginAction ? Can you post that JSP as well.. Also in your web.xml i was not able to see any TLD declaration of the struts html,bean tlds. Have you also made sure that struts.jar is in WEB-INF/lib directory ?

Please answer this questions in order to help you more precisely.

Yogendra N Joshi.
[ October 31, 2006: Message edited by: Yogendra Joshi ]

Meri Zindagi Hain Tab Tak.. Jab Tak Tera Sahara.... Har Taraf Tu Hi Tu Hain SAI Tera Hi Hain Nazara.....
arulraj michealraj
Greenhorn

Joined: Mar 02, 2005
Posts: 28
Hi friend,


This is the jsp page which i am using.


<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<html:html>
<title>
This is Login page
</title>
<body>
<html:form action="/LoginAction">
<table>
<tr>
<td align="left">
User Name:
</td>
<td align="right">
<html:text property="username" size="30" maxlength="30"/>
</td>
</tr>
<tr>
<td align="left">
Password:
</td>
<td align="right">
<html:text property="password" size="30" maxlength="30"/>
</td>
</tr>
<tr>
<td align="right">
<html:submit>
Save
</html:submit>
</td>
<td align="left">
<html:cancel>
Cancel
</html:cancel>
</td>
</tr>
</table>
</html:form>
</body>
</html:html>
arulraj michealraj
Greenhorn

Joined: Mar 02, 2005
Posts: 28
i have verified that struts.jar is in lib directory and stored tld file in WEB-INF directory.


The control goes to action class and there i have given a print statement. That is not displayed in console of server. There is no error in action class. I can see the the text like :http://localost:8080/LoginAction.do" once i submit the form. That is what i was wondering that server doesn't show any error.
RoshaniG Gopal
Ranch Hand

Joined: May 15, 2006
Posts: 180
Hi arulraj,
<forward name="success" path="com/atroad/ui/success.jsp"/> </action>
From the structural heirchary,I think that your JSP is in the WEB-INF. And that is why it is not being displayed.
If at all, remove it from there and then it would work fine.
Secondly, if the SOP is not printed, then it doesnt go to your action class. Please put some SOP in the ActionForm and then check.
Regards,
Roshani
[ October 31, 2006: Message edited by: RoshaniG Gopal ]

Regards,<br />Roshani
arulraj michealraj
Greenhorn

Joined: Mar 02, 2005
Posts: 28
The control goes to actionForm, but not to Action class.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The signature of the execute method in your action class is definitely a problem. It must have exactly the following signature:



If it doesn't, Struts won't call it.


Merrill
Consultant, Sima Solutions
arulraj michealraj
Greenhorn

Joined: Mar 02, 2005
Posts: 28
I have changed method definition as you said in action class. It is working fine. Thanks...............
 
jQuery in Action, 2nd edition
 
subject: nothing is happening in action class when i submit a page(struts )
 
Similar Threads
org.apache.jasper.JasperException: Module 'null' not found.
I am unable to resolve the exception
Need Help on struts....
please help me error comes on my struts application see the source code for details
Kindly help me in fixing the bug . error 404