Wednesday, 29 July 2009

Eclipse Galileo and Struts2

I was quite surprised with how many people came to my blog and read my earlier post on how to create a blank Struts2 project and start using this framework in NetBeans 6.5

With a release of new Eclipse, I thought it would be interesting to do the same thing, but now in this IDE.
As you probably already know, Eclipse is one of the famous and certainly one of the best Java IDEs.
Well, about a month ago people from Eclipse foundation released a 3.5 version of Eclipse, called Galileo.

I develop almost all my project using NetBeans, and have never done any Struts2 programming using Eclipse.
That is why I decided to write a post on how to create a Struts2 example in new Eclipse release: Galileo. That's quite fun because that way I (we) get to learn on how to use Struts2 in Eclipse, and get to see Galileo in action a little bit closer…

Note: In this post, I’ll use much of the text , entire source code and application logic from my previous post and concetrate only on the differences between these two IDEs.


So, let’s get started:

First of all we need Eclipse Galileo. Go to the http://www.eclipse.org/downloads/ and download Eclipse IDE for Java EE Developers.

Next thing we need is Struts2 itself. Go to http://struts.apache.org/2.x/index.html and download the latest version of Struts2.
I downloaded struts-2.1.6-all.zip
You won't be needing all the libraries in it. Just 6 of them. Because of this, you can download essential dependencies only.

When you download one of these archives, extract it to some location, for example: c:\Struts2

It is now time to start a new project. Start Eclipse Galileo.


Click file --> new --> Dynamic web project



Let’s call this project GalileoStruts2Example
I’ll use Tomcat 6 . You can use some other server that you have available , it is completely up to you.






Click Finish.

Your project tree will look like this:







Now, in order to use Struts2 libraries, let's add those essential dependencies to project:

Right-click on the project --> properties --> Java Build Path , select Libraries tab and click on the “Add External JARs” button.

Go to folder where you extracted Struts2 libraries and select ( add to project ) following files:

- struts2-core-2.1.6.jar
- freemarker-2.3.13.jar
- ognl-2.6.11.jar
- commons-fileupload-1.2.1.jar
- commons-logging-1.0.4.jar
- xwork-2.1.2.jar


Most of the tutorials on the web are written for older version of struts2, at the time when commons-fileupload-1.2.1.jar was not mandatory, so even when following all the steps in tutorial , you just couldn't get your project to work ( with newer version of Struts2 ) !

Now, your project will look like this:



Now, copy these six JARs into the “lib” folder located in the root of WEB-INF folder.






These files will be uploaded to App Server , and a deployed application will use it.
We could put this files into main lib folder of application server, but it is most probably better this way...

We need to create one more folder in the root of the WEB-INF , and name it "classes".
This is where you will create struts.xml, and if needed - a struts.properties file.

I'll put all my JSP's into new folder, "jsp" , which I will create in the root of "WebContent" folder.

All Java code that we write, we will place into some package in the "Java Resources: src" folder.
I'll create one now, called "struts2Example" and a "Hello" Class in it.
If you use validaton, put all Validation XMLs inside class's package too...






This is how, at minimum, your Struts2 project structure should look like.


I'll create one small Struts2 application now. Nothing complicated.
User will enter his name, and press "submit" and other page will open , saying Hello to this user.

So, let's first create a Java class extending ActionSupport class , named Hello, inside Struts2Example package.
Let's make it to look something like this:

package struts2Example;
import com.opensymphony.xwork2.ActionSupport;


public class Hello extends ActionSupport
{
private String name, message;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMessage() {
return "Hello " + getName();
}
public void setMessage(String message) {
this.message = message;
}
}

We now need two JSPs, for example "nameinput.jsp" and a "response.jsp"
Each JSP needs to contain this line, in order to use struts2 custom tags in it:

<%@ taglib prefix="s" uri="/struts-tags" %>

nameinput.jsp:


response.jsp:



Let's create an XML validation file for Hello class, and make a name property mandatory.

Hello-validation.xml:

<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">

<validators>
<field name="name">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>Please enter name</message>
</field-validator>
</field>
</validators>


Let’s see how our project tree looks at this stage:



There's only 2 things left for us to do:

Edit struts.xml, and web.xml:

struts.xml must be located in “classes” folder located in the root of WEB-INF folder:






This is where place a file struts.properties if we need to use it, as well…

web.xml:






And if we press “Run” button, and choose a server on which it is supposed to run




we’ll get something looking like this:




But don't worry. Everything is OK, we just didin't handle default page...
If we append entername.action on the URL , our new application will open:


If we do not enter name and press “submit”:



but if we do enter name and press “Submit”:



So, I hope I helped you to understand how to create an empty struts2 project in Eclipse Galileo.

At the end, our project looked like this:





A small conclusion of mine: great thing about Eclipse is that you can do just about everything with it , with just a little few extra settings and installations...
Unfortunately, for me - many things and options remained a little bit more complicated and unintuitive regarding to some other IDEs. That is such a shame!
Nevertheless , for me , Eclipse continues to be one of the best choices!.

Enjoy Struts2 and Galileo!


76 comments:

martha said...

I recently came accross your blog and have been reading along. I thought I would leave my first comment. I dont know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.


Susan

http://8080proxy.com

Brad said...

Excellent getting started tutorial.

trying to create a project from scratch or using Maven architypes wasn't working for me and this is the first set of instructions where "it just worked".

Thanks and well done.

Darko Kalinic said...

Hi Brad!

I'm glad my post helped you...

Anonymous said...

Thanks a lot for simple working tutorial. I always look for tutorials which simply lets me run a concept without getting into complex example logic.
But I had to insert "init-param" tag into web.xml to make it run, Could you please tell me what could be the reason.

Darko Kalinic said...

Hi, I'm glad you like the post.

Can you , please , confirm which application server are you using and what version of it?

Also, what version of struts are you using?

Which "init-param" parameter you exactly had to enter?
Can you , please, provide us your web.xml?

Artashes Hovasapyan said...

Very good newbie tutorial!

Just one small suggestion regarding libraries. Instead of adding them first to Java Build Path then to WEB-INF/lib it is much easier to add them to Java EE Module Dependencies. This way those libraries will be automatically resolved to WEB-INF/lib at deployment time.

Artashes Hovasapyan

Darko Kalinic said...

Hi , Artashes!

I'm glad you like it!

Yes, your suggestion sound like a very good idea! ;-)

Omi said...

Hi Darko Kalinic !!!
Thanx. This blog is excellent.
This is very simple to understand for a student like me who is new to struts.

thanx again.

barkha said...

Hi Darko!!!

I've just started my journey towards Galileo and Struts2 and this post has really helped me a lot to get boosted up..

And i've a query regarding name space error as i've been facing this error from last few days,so could you please suggest me how to over come this problem?i mean how to manage this default page?

Thanks in advance buddy!!!

With Regards,
Barkha Jasani

Darko Kalinic said...

@Omi:

Hi, I'm glad you like it...
Hope to see you here again often...

@barkha:

There are probably many examples how this can be done, and probably a pro one, but I use one that is the easiest for me:

Make index.jsp in root of your web site ( application ) and inside it's HEAD tag insert:

(<) META HTTP-EQUIV="refresh" CONTENT="0;URL=some_starting_point.action" (>)
(I put "<" in brackets because I couldn't write HTML tag in this comment )

where some_starting_point.action is the name of some action you created.

That way, every time you open a link to your application, you will be automatically redirected to your starting point...

barkha said...

Hi Darko Kalinik,

Thank you very very much for your kind support,i'm very glad that finally i've done it by placing my index.jsp under Webcontent folder instead of root of my app as it was not working with that case :)

Thanks again buddy..

Barkha Jasani

Darko Kalinic said...

No,thank you for visiting my blog...

Yes, in Wecontent, that is your root when you deploy application...

barkha said...

Oh!!! now i got you..

Anywayz here i'm facing refreshing problem.i've changed my index.jsp but after restarting server in Eclipse itself,i'm not getting refreshed o/p as i'm getting with export war deploy option(externally deploying war on tomcat).

Why is it not getting refreshed with Eclipse itself?as its working properly with export war option..

Darko Kalinic said...

Hi, barkha!

I'm affraid I didn't understand you quite...

And what is "o/p" ? :-)

barkha said...

Hi Darko,

I've resolved this problem myself,well o/p stands for output :)

here i'm ready for the new query,never mind ;)i wanna create a new project but don wanna follow each and every steps every now and then i.e. starting from File > New > Dynamic Web Project and so on..rather i prefer copy and paste my existing project then refactor>rename in order to create my new project in galileo itself.now i'm facing the problem while running both of the application on Tomcat as it's taking same context path for both the applications though i renamed the previous application's name.do you know from where can i change the context path of the new application in Tomcat which is there in Galileo?as we can do in case of external deployment of war on Tomcat with just changing the Folder name in it..

Thanks,
Barkha

Darko Kalinic said...

This should be available through IDE

Unfortunatelly I don't use eclipse for web development, so I don't have enogh struts + eclipse experience to help you with this...

There should be an option like "change context path" or just "context path" option for project inside eclipse...

Sorry, try some eclipse related forum...

barkha said...

Hi Darko,

Thanks for your reply,anywayz i'ad a nice stay here,thnx again :)

Barkha

amitnigam said...

hi Darko,

Me too like you, means till now I have used only netbeans and newbee for both galileo and struts 2. I found your blog quite to the point and very helpful. but i was just wondering why do we need to copy all the jars into web-inf/lib even when we already have included the external jar? can you shed some light on it.
Thanks

amitnigam said...

I am getting errors:
Unable to load configuration. - bean - jar:file:/D:/netapp2/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/StrutsHW/WEB-INF/lib/struts2-core-2.0.9.jar!/struts-default.xml:14:148
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:395)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:452)
at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:201)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:397)
at org.apache.catalina.core.ApplicationFilterConfig.init(ApplicationFilterConfig.java:108)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3696)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4343)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: Unable to load bean: type:com.opensymphony.xwork2.util.ObjectTypeDeterminer class:com.opensymphony.xwork2.util.GenericsObjectTypeDeterminer - bean - jar:file:/D:/netapp2/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/StrutsHW/WEB-INF/lib/struts2-core-2.0.9.jar!/struts-default.xml:14:148
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:224)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:101)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:169)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)
... 21 more
Caused by: java.lang.ClassNotFoundException: com.opensymphony.xwork2.util.GenericsObjectTypeDeterminer
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
at com.opensymphony.xwork2.util.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:146)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:195)
... 24 more
Nov 4, 2009 10:47:50 PM org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart

I am using following jars:
commons-fileupload.jar
commons-logging-1.1.1.jar
freemaker.jar
ognl-2.6.11.jar
struts2-core-2.0.9.jar
xwork-2.1.3.jar

Please suggest correct combination of jar versions.
Thanks

Darko Kalinic said...

Because, the jar files that we include in our "web-inf/lib" folder are to be deployed to AS, so that AS can use all the dependencies it needs when running our application ( there are no struts jar files inside the server itself )...

Included external jars are there for us in order to write code that uses classes inside included JARs.

Here are the JAR files that I use:

commons-fileupload-1.2.1.jar
commons-logging-1.0.4.jar
freemarker-2.3.13.jar
ognl-2.6.11.jar
struts2-core-2.1.6.jar
xwork-2.1.2.jar

Vatsav said...

Very good article. Thanks. I think it would have been better if we can download your source.

Mady-Censored said...

Good one...
was searching for something like this from few days

Thanks for your time

Darko Kalinic said...

Hi Vatsav , hi Mady-Censored.

I'm glad you like it...

Anonymous said...

hi darko..
i've just started 2 u se n learn eclipse n struts2.. i've tried your tutorial bt i'm getting a few errors n cant run it..

i had errors in 2 files.. hello.java struts.xml.. i've applied quick fix in hello.java n it solve it.. in struts.xml, i've given this error message..

The content of element type "package" must match "(result-types?,interceptors?,default-interceptor-ref?,default-
action-ref?,default-class-ref?,global-results?,global-exception-mappings?,action*)".


i've just downloads eclipse about a month ago n i think its the latest version.. i'm also using apache tomcat v6.0,and struts-2.1.8.1..

anyway, this is a really good tutorial..
thanks..

Darko Kalinic said...

Can you show us your struts.xml ?

Vijayalakshmi said...

Hello Darko,

Really the material is superb!
Thanks a lot. Keep it up.

Viji.

Anonymous said...

nice tutorial..got lost at first but did it again with a clean slate. eventually it worked. thanks!

Darko Kalinic said...

I'm really glad you like it. Hope to have you here again...

souvik said...

Hi Dev this is excellent tutorial
well I just want to know is there ne way to run it as soon as i click run on server from eclipse I mean entername.action will be taken automatically.
Thanking you!!!!!

souvik said...

Hi Dev this is excellent tutorial
well I just want to know is there ne way to run it as soon as i click run on server from eclipse I mean entername.action will be taken automatically.
Thanking you!!!!!

Sachin said...

Hi,

I am Sachin..
I have replicated exactly what you have tutored. But I get this error:
Mar 6, 2010 7:38:47 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
WARNING: Could not find action or result
There is no Action mapped for namespace / and action name entername. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:178)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:595)

Can you please help...

Anonymous said...

Hi Dark,
when i cam trying to run metoned your application..
I am getting below mentioned exveption :
------
Mar 8, 2010 4:54:31 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:TestAppStruts' did not find a matching property.
Mar 8, 2010 4:54:31 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre1.5.0_15\bin;.;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre1.5.0_15/bin/client;C:/Program Files/Java/jre1.5.0_15/bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\
Mar 8, 2010 4:54:31 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8000
Mar 8, 2010 4:54:31 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 734 ms
Mar 8, 2010 4:54:31 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Mar 8, 2010 4:54:31 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.16
Mar 8, 2010 4:54:32 PM org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter struts2
java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.FilterDispatcher
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1360)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1206)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:249)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:397)
at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:108)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3709)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4356)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Mar 8, 2010 4:54:32 PM org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart
Mar 8, 2010 4:54:32 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/TestAppStruts] startup failed due to previous errors
Mar 8, 2010 4:54:32 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8000
Mar 8, 2010 4:54:32 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Mar 8, 2010 4:54:32 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/31 config=null
Mar 8, 2010 4:54:32 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 575 ms
-----
where is the prolbem, can you please me ..

Anonymous said...

Hi Darko,

Everything looks the same before your append the entername.action. However, even after I changed the URL, I still have the same error. Could you solve it? Thanks.

vinoth said...

was a nice tutorial...helped me a lot and it had put away my fears

vinoth said...

was a nice tutorial...helped me a lot and it had put away my fears

vinoth said...

in web.xml welcome file list name should be nameinput.jsp; in nameinput.jsp the tag is missing without which the error wont be displayed

swapnildev said...

Hi Darko,
Thanks a lot.
This is my first ever project on struts

Darko Kalinic said...

swapnildev, you're welcome!

Vick Fisher said...

Thanks for the post!

Several of the struts-related jars have been upgraded to a different version in struts-2.1.8.1.

xwork jar kept the same version, but changed the name:

xwork-2.1.6.jar =>
xwork-core-2.1.6.jar

Vick Fisher said...

Thanks for the post!

Several of the struts-related jars have been upgraded to a different version in struts-2.1.8.1.

This jar kept the same version, but changed the name:

xwork-2.1.6.jar =>
xwork-core-2.1.6.jar

Darko Kalinic said...

Vick, thank you for that valuable information.

I hope someone would need it...

preetha said...

Hi Darko Kalinic!

I am a newbie to this who is in crisis of learning struts. This is really awesome tutorial. Thank you so much.

feroz site said...

hi Darko,

Thanks a lot for tutorial.
can u help me, how to do database connection in struts2........
can u send some materials on it feroz.pasha18@gmail.com

Anonymous said...

Thanks...Its nice tutorial

Anonymous said...

hi Darko Kalinic...i got this error in Eclipse browser...
HTTP Status 404 - There is no Action mapped for namespace / and action name entername.

type Status report

message There is no Action mapped for namespace / and action name entername.

description The requested resource (There is no Action mapped for namespace / and action name entername.) is not available.


--------------------------------------------------------------------------------

Apache Tomcat/5.5.27




wt is missing..?pls tell me..

sri said...

I want struts plugin-in

Anonymous said...

Neat simple and Nice tutorial. Will try out.
Thanks for your effort.

Anonymous said...

hi darko, thanks to you. It really helped me not to learn struts 2 though but in another thing. I was unable to install log4j in eclipse galileo and tried it all day. I used to Right click on webapps folder in project explorer mode and then using build path tried to install into the library log4j.jar. But however i tried eclipse refused to find it. But after following ur way i was able to load log4j and got the logs also.
You said it right, though its great, its so complicated to learn and add specially these library things into the classpath that is taking the maximum time. Hope for some early solution. Thank you once again. :-)

Anonymous said...

The article is good, but i dont understand why the need to put our password also to write comment !!!!!

Darko Kalinic said...

You're welcome ;-)

Anonymous said...

hi,

my validation errors will be displayed, but the errors are not reseting when i fill all my fields.i am unable to solve this problem.

Anonymous said...

Hey Darko,

I did exactly as u demonstrated in the example, its really good and so far the easiest example i came across...

But still i am having some problems when i hit the URL its giving me URL resource not found error...

my web,struts.xml are same as yours...

Any suggestions on the same will be really helpful.

Thanks,
Ashish

Darko Kalinic said...

Anonymous1:

You probably did not set input fields names?

Anonymous2:

I can't help you with this with only so few info. You obviously missed something. If you had done EVERYTHING as I said, it would work...

Anonymous said...

"Hey Darko,

I did exactly as u demonstrated in the example, its really good and so far the easiest example i came across...

But still i am having some problems when i hit the URL its giving me URL resource not found error...

my web,struts.xml are same as yours...

Any suggestions on the same will be really helpful.

Thanks,
Ashish"

Hey Darko,

First thing i was getting Error FilterStart on my console ... It was not giving me any other message... What i did was i changed my Tomcat 5 to Tomcat 5.5
Then it gave me a complete stacktrace which was Class Not Found Exception...
Then i simply changed some jars and added javaassist.jar and it worked...

Thanks,
Ashish

Jigar said...

Its very good blog to understand the struts2.
I am reading struts2 from

http://jigarnagar.wordpress.com/category/java/struts2/

blogs.

Anonymous said...

Hi Darko,

Even after adding entername.action to the url , the browser shows me same 404 error.

I checked struts.xml file, everything is same as your file.

Please advise.

Thanks,
Pramod

Anonymous said...

This is my struts.xml file
404 error is appearing after entering entername.action









/jsp/nameinput.jsp



/jsp/nameinput.jsp
/jsp/response.jsp

Darko Kalinic said...

@Jigar:

Welcome to my blog, and thank you for the good link! ;-)

@Anonymous:

Unfortunatelly, I can't see your struts.xml . Until I can see it: You probably didn't do everything as I explained... Please check everything again and confirm you mapped web.xml and struts.xml as I suggested...

Nandhini said...

Thanks for your nice tutorial about struts 2.Its very useful.

I followed the same steps as mentioned in the blog.
But I am getting error 404 : There is no Action mapped for namespace / and action name entername.

I have used the same struts.xml and web.xml given here.

Could you please tell me where the problem lies?

Anonymous said...

Very nice to start..
But I had noticed one change to my project i.e.adding commons-io-1.3.2.jar to lib

I am getting output page but no text. A blank welcome page is my output.
is the statement good enough to print output?

Any Help appreciated.

Mohamed Azoor said...

Hi thank you for your tutorial. it is very useful for whom start the struts2 projects.

I want to say some think now struts2 community released struts2.2.1.1.

when anyone try this tutorial you will face some inconveniences. I solved that. so my responsible to say to all.

1st one is please include commons-io-VERSION.jar also. in this tutorial it is not mentioned.

2nd one is the new distribution of struts2 library pack contain ognl-3.0.jar. it will caused filter dispatcher initialization exceptions. to avoid this include ognl-2.6.11.jar instead of ognl-3.0.jar.

thank you.

Darko Kalinic said...

Hi Mohamed!

Thanks a lot for sharing that info!

I believe many will find it very usefull!

Praveen said...

Hey dude,

I am a beginner with struts. I have been searching in the internet from the past 3 days and came across many struts starter app, but there was a small prob, i.e each time i added struts.xml from eclips galileo, it used to go into Java SRC folder and my apphad failed. After looking at ur tutorial i put in in the web-inf classes manually(eclipse by default takes struts.xml)into java src. But now I am happy, urs was the 1st successful app i ran. thank u soooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo much.

Nitilaksha said...

Great!!!!

Good Work dear It will helps a lot for beginners. Keep posting..

Darko Kalinic said...

Praveen, Nitilaksha
I'm glad I could help!
Welcome to my blog!

jaypatel512 said...

Your blog seems to be perfect. As suggested by few of our readers, can you please provide us with the eclipse compatible source code. This really helps getting started with eclipse.

Its offcourse not because we are lazy, its that I really messed up many times while doing this.

Thanks in advance.

- Jay.

JAIGOPAL said...

This is a really good article. I have been trying to configure struts2 properly with eclipse and i was unable to until i came across ur article. Thanks a ton!!

Pratap said...

Wow!!!

Its working Great...

Thank you!!!!

Pratap said...

Wow!!

Its working great,

Thank u so much!!!

Will keep in touch......

meenakshi said...

Thanks a lot!!!!
The tutorial was good...... n finally i ran my 1st struts application

gahlot said...

hi darko!
m getting HTTP status 404 resourse not found error
please help.

Gokul said...

Awesome One!!! I tried many tutorial sites it failed me. But urs was great and gave me output..

deeps said...

hey!!i tried many tutorial websites..no struts2 example is working..i always get http status 404 error..why is this happenning??

Bhaskar Jyoti Sharma said...

Hi Darko,

I am learning Struts and having some difficulty in deploying my first project. Can you please help?

Anonymous said...

if i clean the apache tomcat server in eclipse the uploaded files will be deleted , but i dont want that files to be deleted... give me solution soon please...

ashu said...

Thanx for this nice tutorial.

BUt I am facing a problem,
I am implementing it in Eclipse Indigo and getting a "java.lang.NullPointerException" while calling the action class.
I am using the Websphere Application Server.