aspose file tools*
The moose likes Struts and the fly likes action mapping problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "action mapping problem" Watch "action mapping problem" New topic
Author

action mapping problem

priya web
Greenhorn

Joined: Sep 29, 2006
Posts: 2
I have the following mapping in my struts-config file. The showLogin.do page shows the login page (which has the actual login form) and this action mapping works. Since I am using validation, it also displays required errors for username and password back on the login.do page. However when all the form fields are entered correctly it show me a blank page.

The problem is the other mapping which calls LoginAction does not work. There are no errors shown in the server logs.. I have a print statement inside the LoginAction on the very first line of the execute() method but it does not print anything. I am assuming that it does not reach LoginAction. I am not sure what I am doing wrong because I dont see any errors. Can anyone please help me?

<!-- Form Bean Definitions -->
<form-beans>
<form-bean name="loginForm" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="userName" type="java.lang.String">
</form-property>
<form-property name="password" type="java.lang.String">
</form-property>
</form-bean>
</form-beans>
<!-- Action Mapping Definitions -->
<action-mappings>
<action path="/login" type="edu.test.action.LoginAction" name="loginForm"
scope="request" validate="true" input="/WEB-INF/jsp/login.jsp">
<forward name="success" path="/WEB-INF/jsp/login-success.jsp"></forward>
</action>
<action path="/showLogin" forward="/WEB-INF/jsp/login.jsp">
</action>
</action-mappings>


Here is my LoginAction code

public class LoginAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletRequest response)
throws Exception {
System.out.println("In action");
return mapping.findForward("success");
} }


Here is my login.jsp file

<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/tld/struts-bean.tld" prefix="bean" %>
<html:html><HEAD><TITLE></TITLE></HEAD><BODY>
<html:errors/>
<TABLE><html:form action="/login" method="post">
<TR><TD>Username:</TD><TD><html:text property="userName" /></TD></TR>
<TR><TD>Password:</TD><TD><html assword property="password" ></TD>
<TR><TD>Submit</TD><TD><html:submit value="Login"/> </TD></TR>
</html:form></BODY></html:html>
[ October 10, 2006: Message edited by: Bear Bibeault ]
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
What's the mapping you have done for struts in web.xml? Usually the form will have some suffix like /login.do.

Just a question: Are you sure you are able to see the Login.jsp which is inside WEB-INF folder?
[ September 29, 2006: Message edited by: Purushothaman Thambu ]
priya web
Greenhorn

Joined: Sep 29, 2006
Posts: 2
This is my web.xml file
<servlet>
<servlet-name>ActionServlet</servlet-name>
<display-name>ActionServlet</display-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/conf/struts-config.xml</param-value>
</init-param>
<load-on-startup>-1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ActionServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<taglib>
<taglib-uri>/WEB-INF/tld/c.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/c.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/tld/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/tld/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-html.tld</taglib-location>
</taglib>


Usually the form will have some suffix like /login.do.
My form has /login and I have *.do in ActionServlet.. I tried doing a /login.do also for the form in the login page and it makes no difference

>Just a question: Are you sure you are able to see the Login.jsp which is >inside WEB-INF folder?
Yes because I have mapped it
<action path="/showLogin" forward="/WEB-INF/jsp/login.jsp">
</action>

Since I have used validation framework, the validation works on the login page and it says missing username etc.. but when everything is correct it does not go to the LoginAction. I have a print statement inside action but it doesnt work. I am using Struts 1.2.9...
Raji Balakrishnan
Greenhorn

Joined: Jan 19, 2005
Posts: 5
Hi Priya,

Where you able to solve the problem? I am also facing the same problem. Let me know if you find any solution to fix it
sajan chandran chandran
Greenhorn

Joined: Oct 10, 2006
Posts: 2
Hi Priya..

Am also not sure what the problem is.But try change and see the <load-on-startup>-1</load-on-startup> instead of -1 try to put any number greater than zero.

Thanks,
Sajan.C
sure nandu
Greenhorn

Joined: Oct 16, 2006
Posts: 18
Hi Priya,

i copied your all files and tried to execute. it was showing the same problem.

then there was error in your Action class. In your execute method you have given fourth paramater as HttpServletRequest. it has to be HttpServletResponse. change it and it will work.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: action mapping problem