• 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

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

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
arulraj michealraj
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
arulraj michealraj
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The control goes to actionForm, but not to Action class.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
arulraj michealraj
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have changed method definition as you said in action class. It is working fine. Thanks...............
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic