aspose file tools*
The moose likes Struts and the fly likes I think execute method is not executed...(confused) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "I think execute method is not executed...(confused)" Watch "I think execute method is not executed...(confused)" New topic
Author

I think execute method is not executed...(confused)

Rajeev roushan sharma
Ranch Hand

Joined: Jan 28, 2010
Posts: 50
I am pretty new to struts. Not able to execute simple program. Any help will be appreciated...... Here goes all the files detail.

I am not getting any errors but execute method is not redirecting to welcome.jsp. my feeling is execute method itself is not working.

Index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>welcome page</title>
</head>
<body>
<html:form action="lookup">
Enter your user ID : <html:text property="uname" /><br/>
Enter your pass : <html:password property="upass" />
<html:submit/>
</html:form>
</body>
</html>
Lookupactionform.java
import org.apache.struts.action.ActionForm;


public class Lookupactionform extends ActionForm {

/**
*
*/
private static final long serialVersionUID = 1L;
private String uname=null;
private String upass=null;
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public String getUpass() {
return upass;
}
public void setUpass(String upass) {
this.upass = upass;
}


}
lookupaction.java
import java.io.IOException;

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

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


public class lookupaction extends Action {
public ActionForward execute(ActionMapping mapping, HttpServletRequest request,HttpServletResponse response, ActionForm actionForm) throws IOException, ServletException{
// String target=new String("success");
/*if(actionForm!=null)
{
Lookupactionform lookupForm = (Lookupactionform)actionForm;
String username=lookupForm.getUname();
String usepass=lookupForm.getUpass();
request.setAttribute("uuname", username);
request.setAttribute("uupass", usepass);
}*/
System.out.println("action called");
return (mapping.findForward("success"));
}

}
welcome.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Welcome page</title>
</head>
<body>
your name is <%=request.getAttribute("uuname") %><br/>
your pass is <%=request.getAttribute("uupass") %>
</body>
</html>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>allstrts1demo</display-name>
<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>

<welcome-file-list>
<welcome-file>Index.jsp</welcome-file>
</welcome-file-list>
</web-app>
struts-config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<form-beans>
<form-bean name="LoginForm" type="Lookupactionform" />
</form-beans>
<action-mappings>
<action path="/lookup" name="LoginForm" type="lookupaction">
<forward name="success" path="welcome.jsp" />
</action>
</action-mappings>
</struts-config>
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.

And welcome to JavaRanch!
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

You have a System.out.println("action called"); in your execute method, is this message getting displayed on the console (or logs)??


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Rajeev roushan sharma
Ranch Hand

Joined: Jan 28, 2010
Posts: 50
No Ankit, it is not printing the value of System.out.println("action called");
Rajeev roushan sharma
Ranch Hand

Joined: Jan 28, 2010
Posts: 50
I need to resolve the same as soon as possible.. please help....
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

People aren't going to try and figure it out if it isn't properly formatted.

UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.
Rajeev roushan sharma
Ranch Hand

Joined: Jan 28, 2010
Posts: 50
Rajeev roushan sharma wrote:I am pretty new to struts. Not able to execute simple program. Any help will be appreciated...... Here goes all the files detail.

I am not getting any errors but execute method is not redirecting to welcome.jsp. my feeling is execute method itself is not working.

Index.jsp


Lookupactionform.java


lookupaction.java

welcome.jsp


web.xml


struts-config.xml


David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Are there any errors in the log on startup or on action submission? What version of Struts are you using?
Rajeev roushan sharma
Ranch Hand

Joined: Jan 28, 2010
Posts: 50
No, I am not getting any errors. After i click on submit button getting logs :


[Thumbnail for strutslib.gif]

Rajeev roushan sharma
Ranch Hand

Joined: Jan 28, 2010
Posts: 50
I am using struts 1.3.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I don't know what that screenshot is supposed to be, but in the future, if you're trying to show textual information, just get a directory listing.

The Struts libraries should be deployed with the application, not in the Tomcat lib directory.
Rajeev roushan sharma
Ranch Hand

Joined: Jan 28, 2010
Posts: 50
The same libraries are deployed with application.... Can anyone try my code running ?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Here's a bunch of things to do:

- Remove the Struts libraries from the Tomcat lib directory. Deploy them *only* with the application. Post what libraries you're deploying.
- Put your classes in a package.
- Use standard Java naming practices.
- Don't mix case all the time in your JSP filenames; it's confusing.
- Fix the signature of your execute method.
 
jQuery in Action, 2nd edition
 
subject: I think execute method is not executed...(confused)