Hi,
I am very new with
Struts MVC project. I have written a simple hello world project, when I run this project, it shows the index page, but after that it is not working and even not giving any error in console also. I am using RAD 7.x as editor and Websphere as server and Struts1.3. My project business is like that,
JSP pages at view
1. index.jsp --> wher user enter the name or keep blank
2. success.jsp --> if user enter name then only page show the Name which has enter at index.jsp page
3. error.jsp page --> if user did not enter name at index.jsp pageand click submit then it show error message.
Java classes
1. HelloWorldForm --> for getter and setter
2. HelloWorldAction --> Action page
=====================================================================
-----------------------------code ------
web.xml
-------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>HelloStruts</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>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</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>
<jsp-config>
<taglib>
<taglib-uri>/struts-html</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/struts-bean</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/struts-logic</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>
=================================================================================
====================================struts-config.xml ==================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
<form-beans>
<form-bean name="helloWorldForm" type="org.resource.model.HelloWorldForm"> </form-bean>
</form-beans>
<global-exceptions>
</global-exceptions>
<global-forwards>
</global-forwards>
<action-mappings>
<action path="/helloWorldForm" name="helloWorldForm" type="org.resource.action.HelloWorldAction" input="/index.jsp">
<forward name="success" path="/success.jsp"></forward>
<forward name="error" path="/error.jsp"></forward>
</action>
</action-mappings>
<message-resources parameter="com.ibm.hellostruts.resources.ApplicationResources"/>
</struts-config>
=====================================================================================
=============================================index.jsp===============================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><%@page
language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="/struts-html" prefix="html"%>
<%@taglib uri="/struts-bean" prefix="bean"%>
<%@taglib uri="/struts-logic" prefix="logic"%>
<html>
<head>
<title>index</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="pink">
<form action="/helloWorldForm" method="post">
<p><bean:message key="my.message" />
<p>Enter your name :
<input type="text" name="ename" size="30"/><p>
<input type="submit" value="Submit"/>
</form>
</body>
</html>
============================================================================
=======================================success.jsp============================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><%@page
language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="/struts-html" prefix="html"%>
<%@taglib uri="/struts-bean" prefix="bean"%>
<%@taglib uri="/struts-logic" prefix="logic"%>
<html>
<head>
<title>success</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#AAA8">
<p><bean:message key="my.message"/>
<p><h3>Success!!</h3>
Successfully Added <%=session.getAttribute("success") %>
</body>
</html>
==========================================================================
=======================================error.jsp================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><%@page
language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="/struts-html" prefix="html"%>
<%@taglib uri="/struts-bean" prefix="bean"%>
<%@taglib uri="/struts-logic" prefix="logic"%>
<html>
<head>
<title>error</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<p><bean:message key="my.message" />
<p><h1> This is an error!!!</h1>
</body>
</html>
==================================================================================
===========================================HelloWorldForm.java===========================
package org.resource.model;
import org.apache.struts.action.ActionForm;
public class HelloWorldForm extends ActionForm {
/**
*
*
*/
private static final long serialVersionUID = -1224302756003163541L;
private
String message;
/**
* @return the message
*/
public String getMessage() {
return message;
}
/**
* @param message the message to set
*/
public void setMessage(String message) {
this.message = message;
}
}
==================================================================================
===================================HelloWorldAction.java================================
package org.resource.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.resource.model.HelloWorldForm;
public class HelloWorldAction extends Action {
public ActionForward execute(ActionForm afm, ActionMapping amp,
HttpServletRequest req, HttpServletResponse res) throws Exception{
HttpSession sen=req.getSession(true);
HelloWorldForm hwf=(HelloWorldForm)afm;
String success =hwf.getMessage();
sen.setAttribute("success", success);
if(success.equals("")){
return amp.findForward("failure");
}else
{
return amp.findForward("success");
}
}
}
==========================================
project file structure screenshot have attached along with this
can any one help me out this problem please