This tutorial explains struts 2 with the bare minimum. You won't get lost in the unwanted files under the struts example applications.
You should be comfortable working with eclipse and WTP. I have used eclipse 3.2.2 myself. Any 3.1 or latter should work, although not tested. You will also need web Tools plugins from the curresponding Calisto release.
From eclipse select File -> New -> Project and from the list select “Dynamic Web Project” under the “Web” Group.
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello World !</title>
</head>
<body>
<h1> Struts 2 Hello World </h1>
</body>
</html>
Now if you select run “index.jsp” using “run on the server” option, you can see the JSP page we just created. If you see that, congratulations, we are ready to go to the struts2 tutorial.
At the minimum struts2 requires 4 jar files, and the configuration file “struts.xml”. We also need to make some modification to the project's build settings, so that eclipse will put the class files under “WebContent/classes”. If you know how to do that go ahead and do it. If you don't know, here is how it is done.
Now we need to add the struts 2 jar files to the Web app libray. Copy the following files from struts distribution to the “WebContent/WEB_INF/lib” folder.
I didn't mention the version number because it may change. But make sure you copy everything from the struts example application that comes with the struts distribution.
Now we need to add the struts 2 filter and filter mapping to the web.xml. Add the following line to your web.xml.
Create a files “struts2.xml” under 'HelloWorld/src' and add the following content.
This is the minimum required configuration for struts. Now if you restart tomcat, you should be able to see the same index.jsp page. Now add the following snippets between the package tags.
After restarting tomcat, try accessing '/HelloWorld/HelloWorld.action' , you can see the 'Hello world from struts2!” message on the screen. So your first action worlked, even though you didn't write any !
Comments
struts 2
rajesh.v
91+9349791324
hi i am just add struts2 filter to web.xml
and create struts2.xml and helloWorld.jsp
add action tag to struts2.xml as u said
and did all as explained
but the index page is working try to access /HelloWorld/HelloWorld.action
getting error
************************
SEVERE: Could not find action or result
There is no Action mapped for namespace / and action name
HelloWorld. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:186)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:41)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:494)
****************************************
and till now not add action class just add filter to web.xml
from that gettingthis exception cant find
i did all the thing explained as above
hope fully
with regards
rajesh
similar problem
I had the same problem, but was able to get it working by changing 'struts2.xml' to 'struts.xml'
hope this helps,
zmelvin
working
This example is working fine but u need to rename struts2.xml file to struts.xml
Regards
Jhandu