File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes new to struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "new to struts" Watch "new to struts" New topic
Author

new to struts

Geeta Ravikanti
Ranch Hand

Joined: Mar 26, 2008
Posts: 46
Hi all,
I am new to struts i want to a sample program in struts,for this i did like following


I did every thing for doing the program in struts like Action clss,web.xml,struts-config.xml

here i am sending my path

C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\appstruts\WEB-INF\classes\Aone.java--->this is action class

C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\appstruts\WEB-INF\web.xml,struts-config.xml

C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\appstruts\WEB-INF\lib\-->here i included related jar files

struts-config.xml

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">

<struts-config>

<!-- ========== Form Bean Definitions ============ -->
<form-beans>
<form-bean name="login" type="test.struts.LoginForm" />
</form-beans>


<!-- ========== Global Forward Definitions ========= -->
<global-forwards>
</global-forwards>


<!-- ========== Action Mapping Definitions ======== -->
<action-mappings>
<action
path="/actOne"type="Aone" >

<forward name="valid" path="/jsp/MainMenu.jsp" />
<forward name="invalid" path="/jsp/LoginView.jsp" />
</action>
</action-mappings>

</struts-config>

web.xml


<?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>

<!-- Action Servlet Configuration -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>application</param-name>
<param-value>test.struts.MessageResources</param-value>
</init-param>
<init-param>
<param-name>mapping</param-name>
<param-value>org.apache.struts.action.RequestActionMapping</param-value>
</init-param>
<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>
<load-on-startup>2</load-on-startup>
</servlet>


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

<!-- Struts Tag Library Descriptors -->


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

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

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

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

</web-app>

Aone.java

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import org.apache.struts.action.*;
public class Aone extends Action
{
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest req,HttpServlet res)throws Exception
{
System.out.println("----execute of aone---");
return null;
}
}


but when i am going to excute in tomcat its going to another file
i am clicking on the folder appstruts like following

http://localhost:8082/appstruts/

but its directly going to http://localhost:8082/appstruts/example/HelloWorld.action this link
i changed and i typed there like following http://localhost:8082/appstruts/actOne.do
its giving the error uable to find requsted resorce
what to do
where did i mistaked

please any one help me
kenji kunoichi
Ranch Hand

Joined: Jun 02, 2007
Posts: 46
you havent made any JSP page ? you need a view component right ? when starting struts download struts-blank.war file from the apache website and try to run the war file put the war file in Tomcat's webapps folder . se struts blank is running or not ( first from your services start tomcat )...if tomcat is starting well then try to run the struts-blank.war
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: new to struts