This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Hello World with Struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Hello World with Struts2 " Watch "Hello World with Struts2 " New topic
Author

Hello World with Struts2

Amey Ambulgekar
Ranch Hand

Joined: Nov 22, 2011
Posts: 36
Hello Java friends,

I am beginner to struts2 and yesterday i did a simple Hello World Program but I got an error .

Here is my program and my exceptions .

Struts.xml file ::

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

<package name="default" extends="struts-default" namespace="/">
<action name="getTut" class="org.com.struts.TutAction">
<result name="success">/success.jsp</result>
<result name="failure">/error.jsp</result>
</action>
</package>

</struts>

here is my web.xml ::

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Struts2App</display-name>

<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

</web-app>

and here is my java class ::

package org.com.struts;

public class TutAction {
public String execute(){
System.out.println("Hello.! from struts");
return "success";
}
}

and now what i did run an application and i appended at the end
http://localhost:8080/Struts2App/getTut.action //<--

but i got this error ::

HTTP Status 404 - There is no Action mapped for action name getTut.action/.
type Status report
message There is no Action mapped for action name getTut.action/.
description The requested resource (There is no Action mapped for action name getTut.action/.) is not available.
Apache Tomcat/6.0.35

is my method wrong or what happened and i have added following jar's ::

1]struts2-core-2.3.4.jar
2]commons-fileupload-1.2.2.jar
3]commons-io-2.0.1.jar
4]commons-lang-2.4.jar
5]commons-lang3-3.1.jar
6]commons-logging-1.1.1.jar
7]commons-logging-api-1.1.jar
8]freemarker-2.3.19.jar
9]javassist-3.11.0.GA.jar
10]ognl-3.0.5.jar

friends please help me out. I did program 4 times but still i got same error for that i install and uninstall tomcat6 5-6 times.! friends please help me.!

you can run my program and tell me is there any mistake i did or need to add something. i know problem arising only within either "struts.xml" or "web.xml" but where .?

Thanking you.!



Mohana Rao Sv
Ranch Hand

Joined: Aug 01, 2007
Posts: 485



Post your project Structure.

install and uninstall tomcat6 5-6 times.
You are doing something wrong why you are screwing tomcat. :P


ocjp 6 — Feeding a person with food is a great thing in this world. Feeding the same person by transferring the knowledge is far more better thing. The reason is the amount of satisfaction which we get through food is of only one minute or two. But the satisfaction which we can get through the knowledge is of life long.
Amey Ambulgekar
Ranch Hand

Joined: Nov 22, 2011
Posts: 36
Hello All,

i got the solution for this struts program i just changed jar files means i changed from ::


1]struts2-core-2.3.4.jar to struts2-core-2.0.11.jar <--
2]commons-fileupload-1.2.2.jar kept as it is
3]commons-io-2.0.1.jar kept as it is
4]commons-lang-2.4.jar kept as it is
5]commons-lang3-3.1.jar kept as it is
6]commons-logging-1.1.1.jar kept as it is
7]commons-logging-api-1.1.jar kept as it is
8]freemarker-2.3.19.jar kept as it is
9]javassist-3.11.0.GA.jar kept as it is
10]ognl-3.0.5.jar to ognl-2.6.11.jar <--
11]xwork-core-2.3.4.jar to xwork-2.0.4.jar <--

so it works i am very happy


but still i have one question --> when i download struts2.1.8 jars and use for application then it gives me error such as resource not found .!
why is it so..?

Thanking you all.!


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hello World with Struts2
 
Similar Threads
problem in Struts2 while running an application
Struts2 config error
interceptor problem in struts2
Struts2 "There is no Action mapped for namespace / and action name LoginAction ERROR"
Jsp is not getting displayed in struts2 using eclipse.