• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

web.xml and Struts 2

 
Luigi Quarta
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to make this tutorial work: http://struts.apache.org/2.0.14/docs/hello-world.html

The structure of my webapp is

tutorial/
tutorial/META-INF
tutorial/WEB-INF
tutorial/WEB-INF/web.xml
tutorial/WEB-INF/lib
tutorial/WEB-INF/classes
tutorial/WEB-INF/classes/HelloWorld.class
tutorial/WEB-INF/classes/HelloWorld.jsp
tutorial/WEB-INF/classes/struts.xml

in lib i've copied all the Struts 2 lib's jars
this is my web.xml structure:


this is my HelloWorld.jsp structure:


this is my struts.xml structure:


and this is the HelloWorld.class code:


When i go in the Tomcat admin control panel this web app doesn't run... probably the container doesn't like my web.xml file. Why?
 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This line in struts.xml looks wrong to me



The fully qualified class name is tutorial.HelloWorld and not hello-world.HelloWorld...
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JSP file shouldn't be in the classpath, it should be in either under the webapp root or under /WEB-INF.
 
Luigi Quarta
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i've re-organized my project like this:



index.jsp:


web.xml:


struts.xml


struts.properties


HelloStruts2World.java:


But as before my application cannot be started in Tomcat and if i try to run it with NetBeans I get this error:


I also notice that undeploy the application is impossible cause struts2-core-2.1.6.jar cannot be deleted!
 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This is wrong, the HelloStruts2World action is mapped to HelloStruts2World path, so use

 
Luigi Quarta
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you,
So, every time, only the action name must be provided as action attribute in a form? I've made this change but the application server still doensn't want to run my application
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which Struts 2 libraries are you deploying? If you're deploying "all" of them as you claim it most likely won't work because you won't have satisfied the plugin dependencies. If your logging is configured correctly you'll see errors on startup.
 
Luigi Quarta
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The log folder is empty cause the application server refuse even to start my application... I've imported the minimum library set as described in the struts 2 official tutorial (ognl-2.6.11.jar, xwork-2.1.2.jar, struts2-core-2.1.6.jar, freemarker-2.3.13.jar, commons-logging-1.0.4.jar)

Usually when the server refuse to run an application it's a web.xml question, but the different respect the others times is only in the filter part...
 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are missing the commons file upload library. Download the essential dependencies from here...
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And commons-io.

You *really* need to configure logging--how else will you spot startup errors?!

Application startup errors *are* logged.
 
Luigi Quarta
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excuse me, as you can see this is my first Struts 2 project... i've added to the lib folder common-io e common-file-upload. The project doesn't run but i get several log files:

catalina.2009-09-17.log


localhost.2009-09-17.log:


The error seems to be in the HelloStruts2World class isn't it?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.

You configure the action like this:But that isn't the package you're using in the action itself.
 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As David said, the actual class name of your Action is action.HelloStruts2World. So it should go under WEB-INF/classes/action/HelloStruts2World.class in the deployed archive...
 
Luigi Quarta
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to place my actions class in view/action/ so i should modify the class name but i don't understand how
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change the package name.
 
Luigi Quarta
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've tried many times without result; every time in the log files the action is not found...
What i have to change the name or the package namespace? I've changed the package name into "/view" "/view/action" and athers...
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post your *current* code and configuration.
 
Luigi Quarta
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Code:


Configuration:



Application structure:

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your action class's package doesn't match where it is in the file hierarchy.

You're declaring your action class as:but in the file hierarchy it's:
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And, while it isn't really a problem, if you're using Struts 2.1 you should probably use the 2.1 DTD.
 
Luigi Quarta
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the fast reply, so in my code it should write:

?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened when you tried it?

But no, it should beYou might want to brush up on some basic Java before going too much further--it'll save a lot of time.
 
Luigi Quarta
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now all run perfectly, thank you so much!
It was a class package question, anyway i'll follow your advice and i'll use 2.1 DTD too.

I think i should study better the java pakages and the classpath... Another configuration dubt: actually the result is the "HelloWorld.jsp" placed in the application root, in general i will place the JSP in:



to obtain map the result to the page I should write in the struts.xml sopething like this:


?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I wouldn't place the JSP files in the class directory--they're not classes. I *would* keep them under WEB-INF, but I always keep them in their own directory.
 
Luigi Quarta
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that's a good advice, i'm following the rest of the tutorial on the struts 2 wiki and now many things are clear.
Best regards
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic