• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with my first struts application

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please don't post the same question in multiple threads. I'll close this one for you.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic