• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Sheriff
Posts: 9709
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have a System.out.println("action called"); in your execute method, is this message getting displayed on the console (or logs)??
 
Rajeev roushan sharma
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No Ankit, it is not printing the value of System.out.println("action called");
 
Rajeev roushan sharma
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to resolve the same as soon as possible.. please help....
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, I am not getting any errors. After i click on submit button getting logs :
strutslib.gif
[Thumbnail for strutslib.gif]
 
Rajeev roushan sharma
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using struts 1.3.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The same libraries are deployed with application.... Can anyone try my code running ?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic