aspose file tools*
The moose likes Struts and the fly likes Problem with my first struts application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem with my first struts application" Watch "Problem with my first struts application" New topic
Author

Problem with my first struts application

kiran india
Greenhorn

Joined: Jan 09, 2008
Posts: 2
Hi, all. Iam new to struts. As a part of starting my journey towards struts, I started with a simple struts application. But I am facing problem with either actionForm or actionClass or someother. Here is entire application. Please go through this and help me.

My application location : C:\Tomcat 5.5\webapps\myStruts (In this, My application name is myStruts.)
Contents of myStruts folder : WEB-INF folder, First.jsp, Second.jsp.

C:\Tomcat 5.5\webapps\myStruts\First.jsp code
==============================================
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>

<html:html>
<head>
<title>First.jsp</title>
</head>
<body>
<html:form action="/first.do">
<html:errors />
<table>
<tr>
<td>Enter Your Nick Name: </td>
<td><input type="text" name="nick" /></td>
</tr>
<tr>
<td>Enter Your Lucky Number: </td>
<td><input type="text" name="lucky" /></td>
</tr>
<tr>
<td></td>
<td align="right"><input type="submit" value="Submit" /></td>
</tr>
</table>
</html:form>
</body>
</html:html>

C:\Tomcat 5.5\webapps\myStruts\Second.jsp code
================================================
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>

<html:html>
<head>
<title>Second.jsp</title>
</head>
<body>
<html:errors />
<p><h2>Hai, you are redirected from First.jsp</h2></p>
</body>
</html:html>

Contents of myStruts/WEB-INF folder :
actionForms folder (contains FirstActionForm.java, FirstActionForm.class),
actions folder (contains FirstAction.java, FirstAction.class),
classes (empty) folder,
lib (containing jar files) folder, and
xml files (struts-config, web, tiles-defs, validation, validator-rules).

C:\Tomcat 5.5\webapps\myStruts\WEB-INF\actions\FirstAction.java code
==========================================================================
import javax.servlet.http.*;
//import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.*;
//import org.apache.struts.action.ActionForm;
//import org.apache.struts.action.ActionForward;
//import org.apache.struts.action.ActionMapping;

public class FirstAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
System.out.println("This is from Action class");
return mapping.findForward("success");
}
}

C:\Tomcat 5.5\webapps\myStruts\WEB-INF\actionForms\FirstActionForm.java code
=============================================================================
import org.apache.struts.action.*;
import javax.servlet.http.HttpServletRequest;


public class FirstActionForm extends ActionForm{

private String nick = null;
private String lucky = null;

public String getNick() {
return nick;
}

public String getLucky() {
return lucky;
}

public void setNick(String nick) {
this.nick = nick;
}

public void setLucky(String lucky) {
this.lucky = lucky;
}

public void reset(ActionMapping mapping, HttpServletRequest request) {
this.nick=null;
this.lucky=null;
}

}

C:\Tomcat 5.5\webapps\myStruts\WEB-INF\web.xml code
=====================================================
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

<web-app>
<display-name>Struts Blank Application</display-name>

<!-- Standard Action Servlet Configuration (with debugging) -->
<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>


<!-- Standard Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>


<!-- Struts Tag Library Descriptors -->
<taglib>
<taglib-uri>/tags/struts-bean</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/tags/struts-html</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/tags/struts-logic</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/tags/struts-nested</taglib-uri>
<taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/tags/struts-tiles</taglib-uri>
<taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
</taglib>

</web-app>

C:\Tomcat 5.5\webapps\myStruts\WEB-INF\struts-config.xml code
================================================================
<?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>
<data-sources> </data-sources>

<form-beans>
<form-bean
name="formbean1"
type="actionForms.FirstActionForm" />
</form-beans>



<global-exceptions> </global-exceptions>
<global-forwards> </global-forwards>



<action-mappings>

<action
path="/first.do"
name="formbean1"
type="actions.FirstAction"
validate ="false">
<forward name="success" path="/Second.jsp"/>
</action>

</action-mappings>




<controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>


<plug-in className="org.apache.struts.tiles.TilesPlugin" >
<set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />
<set-property property="moduleAware" value="true" />
<set-property property="definitions-parser-validate" value="true" />
</plug-in>

<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>

</struts-config>


<---Please give me necessary suggestions in my Journey towards Struts--->
I hope this journey with you will leave me and you so much of knowledge.
Thank you.
Robin Rath
Greenhorn

Joined: Jan 07, 2008
Posts: 10
Actually you didn't mention the error details. So it is quite difficult to guess.
But i am thinking you may have mistake in thse lines.
use only one tag library bcz you are using only html tags so
<%@ taglib uri="/tags/struts-html" prefix="html" %> is enough.
Then instead of using this <html:form action="/first.do"> tag use only <html:form action="first.do"> no "/" slash is required bcz you are mentioning clearly first.do
use <html:text property="nick"/> instead of <input type="text" name="nick" />, bcz you are using struts specific html tags.

in struts-config.xml file just modify like below

<action-mappings>

<action
path="first.do"
name="formbean1"
type="actions.FirstAction"
validate ="false">
<forward name="success" path="/Second.jsp"/>
</action>

</action-mappings>

Try it. It may solve your problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with my first struts application
 
Similar Threads
form page cannot find ActionMappings or ActionFormbeans
problem with struts1.1 please help me...
Problem with my first struts application
Very basic question
Trying to Learn Struts: Errors