• Post Reply Bookmark Topic Watch Topic
  • New Topic

please help Struts1.3 simple Dyn web project issue  RSS feed

 
Nirmal Kanti Sahoo
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
projectstructure.jpg
[Thumbnail for projectstructure.jpg]
 
Joe Ess
Bartender
Posts: 9436
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless there is some reason you need to learn Struts 1 (i.e. your employer has an old application that uses it and for some reason cannot upgrade), don't. It hasn't seen an update in nearly 10 years, is officially unsupported and has some glaring architectural flaws that make any non-trivial development painful.
That said, I'm not sure what you mean by "it is not working". Does the form not submit? Does the page go blank? Does it just sit there?
Your best bet to debug your code would be to put log messages in your action methods to see if they are getting called, getting the information you expect and returning the values you want them to.
 
Nirmal Kanti Sahoo
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When ever I click on link at indec.jsp page either for success.jsp and error.jsp page it gives a blank page. Even nothing error are showing at console. page error status 500.
Regarding debug when I started to debug, it goes to ClassNotFoundException.
 
Joe Ess
Bartender
Posts: 9436
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nirmal Kanti Sahoo wrote:Even nothing error are showing at console. page error status 500.

That code means "internal server error", meaning the server encountered an issue processing the request.


Nirmal Kanti Sahoo wrote:
Regarding debug when I started to debug, it goes to ClassNotFoundException.

So what is the full stack trace of the error? Have you checked your server logs?
 
Nirmal Kanti Sahoo
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joe,
Thanks for your reply. But I am extremely sorry , issue yet not fixed. and Other things is that error code is HTTP 404, not 500. I have attached the screenshots. Regarding server log, I don't know how to check. Please help me.
---------------
index.png
[Thumbnail for index.png]
index2.png
[Thumbnail for index2.png]
eoorpage.png
[Thumbnail for eoorpage.png]
 
Nirmal Kanti Sahoo
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi joe,
when i run this project console gives an error message like :
============================================================================================
[5/24/15 12:52:45:755 IST] 00000023 PropertyMessa W org.apache.struts.util.PropertyMessageResources loadLocale Resource com/ibm/hellostruts/resources/ApplicationResources_en_US.properties Not Found.
[5/24/15 12:52:45:765 IST] 00000023 PropertyMessa W org.apache.struts.util.PropertyMessageResources loadLocale Resource com/ibm/hellostruts/resources/ApplicationResources_en.properties Not Found.
[5/24/15 12:52:50:605 IST] 00000023 ComposableReq I org.apache.struts.chain.ComposableRequestProcessor init Initializing composable request processor for module prefix ''
[5/24/15 12:52:50:665 IST] 00000023 CreateAction I org.apache.struts.chain.commands.servlet.CreateAction createAction Initialize action of type: org.resource.action.HelloWorldAction
==============================================================================================================

after that when i try to add classes folder under WEB-INF, it shows message already exist, but there is only lib folder.
 
David Conoc
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nirmal,

Declare <global-forwards> and <global-exceptions> can be very useful, see.
Also comments found into struts-config.dtd file.

For MessageResource, you can put all keys in "FILE"

(null=false,so always get one)
,setting "mode" property, you indicate when the attribute is updated (ie. LOCALE, in case you have more than one)


Hope it helps.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!