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>