It's not a secret anymore!*
The moose likes Struts and the fly likes Struts 2 Hello World - Having Trouble in Starting up 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 "Struts 2 Hello World - Having Trouble in Starting up" Watch "Struts 2 Hello World - Having Trouble in Starting up" New topic
Author

Struts 2 Hello World - Having Trouble in Starting up

Kristian Wijaya
Greenhorn

Joined: May 07, 2014
Posts: 7
Hello all. This is actually my first post, and since I found no 'Intro forum'. I may as well ask.

I'm inspired to learn about the Strut framework. So I looked at some sample codes on the net, like this:

http://www.tutorialspoint.com/struts_2/struts_examples.htm

I'm using Struts 2.3.16.3, and for my Tomcat, I'm using a built-in Tomcat from XAMPP 1.8.3, it's Tomcat 7.

I'm building it using Eclipse and found no problems in building the WAR file. But when I try to run it on my XAMPP, it always gives this error:

type Exception report

message /HelloWorldStruts2/index.jsp (line: 3, column: 40) File "/struts-tags" not found

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: /HelloWorldStruts2/index.jsp (line: 3, column: 40) File "/struts-tags" not found
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:443)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:133)
org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:166)
org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:410)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:475)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1427)
org.apache.jasper.compiler.Parser.parse(Parser.java:138)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:242)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.42 logs.


Or this:

type Exception report

message java.lang.ClassNotFoundException: org.apache.jsp.HelloWorldStruts2.index_jsp

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.HelloWorldStruts2.index_jsp
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:177)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

root cause

java.lang.ClassNotFoundException: org.apache.jsp.HelloWorldStruts2.index_jsp
java.net.URLClassLoader$1.run(URLClassLoader.java:366)
java.net.URLClassLoader$1.run(URLClassLoader.java:355)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(URLClassLoader.java:354)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:132)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:172)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.42 logs.


I will appreciate all help that I can get. Thank you very much and I hope I will be able to learn more here.
Asif Pathan
Greenhorn

Joined: Oct 05, 2007
Posts: 9
    
    1

Hi Kristian,

This error would simply mean that the jar files required to run a struts application are not detected. Please check if the jar files are properly included in lib.

Regards,
Asif
Kristian Wijaya
Greenhorn

Joined: May 07, 2014
Posts: 7
Okay, let's compare the libs I have.

commons-fileupload-1.3.1.jar
commons-io-2.2.jar
commons-lang-2.4.jar
commons-logging-1.1.3.jar
commons-logging-api-1.1.jar
freemarker-2.3.19.jar
javassist-3.11.0.GA.jar
ognl-3.0.6.jar
struts2-core-2.3.16.3.jar
xwork-core.2.3.16.3.jar

Did I miss anything? All of them put in WEB-INF/lib folder. Which seems to be the problem out of these JAR files?

(Or could it be that there's another place I missed out so my Struts 2 does not work in the XAMPP environment?)

Regards,
Kristian
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

Welcome to the JavaRanch!
You are missing at least 4 JAR files:
asm-3.3.jar
asm-commons-3.3.jar
asm-tree-3.3.jar
log4j-1.2.7.17.jar

I recommend starting a new project with the the struts2-blank.war file in the apps directory of the Struts distribution. Extract it and add your own functionality. It's a lot easier than trying to hunt down the dependencies after the fact.
It's also a good idea to show us the corresponding source file when you show us an exception so we know what you are looking at.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Kristian Wijaya
Greenhorn

Joined: May 07, 2014
Posts: 7
Joe Ess wrote:Welcome to the JavaRanch!
You are missing at least 4 JAR files:
asm-3.3.jar
asm-commons-3.3.jar
asm-tree-3.3.jar
log4j-1.2.7.17.jar

I recommend starting a new project with the the struts2-blank.war file in the apps directory of the Struts distribution. Extract it and add your own functionality. It's a lot easier than trying to hunt down the dependencies after the fact.
It's also a good idea to show us the corresponding source file when you show us an exception so we know what you are looking at.


Thanks for the list! I was following that site, and after reading what you posted, I find it weird that he did not list the asm jars as important things to be put in your lib folder.

The asm files are indeed in the lib folder of the Strut download zip file. However, the log4j-1.2.7.17.jar isn't in the lib folder. Good thing it actually exists in that struts2-blank.war file so I can just extract that.

EDIT: I really tried putting the JAR files into the lib. I put them on the project library, imported to WAR, restarted my Tomcat... and still the same result. Maybe it's something else?

I ended up having to try running the struts2-blank.war file in the Struts file... and it ended up displaying this instead:

type Status report

message /examples/struts2-blank/example/HelloWorld.action

description The requested resource is not available.


I really really can't just go put the blank state on a Tomcat and expects it to run without me tinkering the sources a little, can I? I certainly hope there will be help. If my guess is right, there is something on the coding that tells the server to open up a file called 'HelloWorld.action', whereas what I see is that there is the file called 'HelloWorld.jsp'. I have to import from Eclipse and fix it myself first?

Maybe I should give the WAR file of that HelloWorldStruts2. Here it is, I hope it helps.
Asif Pathan
Greenhorn

Joined: Oct 05, 2007
Posts: 9
    
    1

As Joe already pointed out that some of the jars are missing, use the struts blank project as a starting point. (If not, maven usually helps greatly to avoid dependency issues.) In case the issue still persists then it would mean that the jar was not detected as I mentioned earlier. The "/struts-tags" in uri refers to an entry in tld file in struts2-core-2.3.16.3.jar.

Hello Joe .

Regards,
Asif
Asif Pathan
Greenhorn

Joined: Oct 05, 2007
Posts: 9
    
    1

Not all jars are required to run the sample project and hence they are not included in tutorials or getting started sections. That being said, the project won't work as it should without some jars. Also, the sample blank project should run as is on tomcat.
Rgds,
Asif
Kristian Wijaya
Greenhorn

Joined: May 07, 2014
Posts: 7
And like I said before, I've tried running the sample project as-is, and it instead shows such error.

Maybe I have to modify something on my Tomcat application to be able to run Struts 2 framework first? (Note that I'm using Tomcat 7 built in via XAMPP)
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

If you look at the blank app provided with Struts, you should see that your commons-lang file is the wrong version.
I don't have XAMMP, but after I made that change to your WAR, the application worked in Tomcat 6.0.36.
Kristian Wijaya
Greenhorn

Joined: May 07, 2014
Posts: 7
Well, I think I found out the reason why. My XAMPP demands that I put the blank app on the webapps folder, not the webapps/examples folder like the other example pages. Once I have done that, the blank app now works, even if my Tomcat is 7.0.42.

However...

It just loads REALLY long. Did it load fast in yours, Joe? Maybe I should just download a standalone Tomcat just for this.

After doing that process on my app, the result is now a 404 error of "The requested resource is not available". Maybe I should try doing that method of yours (change the commons-lang files), but I think it might not solve the problem. What do yo uthink?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

Kristian Wijaya wrote:My XAMPP demands that I put the blank app on the webapps folder,


Same thing with the standalone Tomcat.

Kristian Wijaya wrote:
It just loads REALLY long. Did it load fast in yours, Joe? Maybe I should just download a standalone Tomcat just for this.


It loaded in seconds for me. Yes, try the standalone Tomcat. If only to rule out other possibilities.

Kristian Wijaya wrote:
After doing that process on my app, the result is now a 404 error of "The requested resource is not available". Maybe I should try doing that method of yours (change the commons-lang files), but I think it might not solve the problem. What do yo uthink?


You must use the correct version of commons-lang if you want your application to work.
Kristian Wijaya
Greenhorn

Joined: May 07, 2014
Posts: 7
It still loaded pretty long for my standalone Tomcat 7.0.42. When I check it, it's that everytime I enter a link there, the cmd prompt would start printing out something like the xml contents, which is A LOT, thus it takes time.

EDIT: It actually works faster for Tomcat 6. Okay, let me try on the others.
Kristian Wijaya
Greenhorn

Joined: May 07, 2014
Posts: 7
Okay, I'm sorry I was away for quite a bit here! I'd like to make a report.

Once I changed the commons-lang JAR file and switched to the Tomcat 6, even my original project that's not from the sample actually works! Except that there's this thing on the cmd of the Tomcat:

WARNING!! FilterDispatcher is deprecated!


But aside of that, it works well. I just wonder if it'll cause trouble later?

Oh, and also since I'm really new with Frameworks, I may as well ask... What are the advantages of using a Framework? Can anyone explain through example? Like for instance:
-When trying to make a login form, why would using Struts 2 be actually advantageous?
-Is there some feature in Java that can only be achieved using Struts 2?

Thanks for the help so far.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

Kristian Wijaya wrote:
But aside of that, it works well. I just wonder if it'll cause trouble later?


You should use StrutsPrepareAndExecuteFilter. FilterDispatcher will likely not be updated and may be removed going forward.

Kristian Wijaya wrote:
Oh, and also since I'm really new with Frameworks, I may as well ask... What are the advantages of using a Framework? .


Any framework should have the benefit of taking care of a lot of the tedious detail work in setting up an application so you can concentrate on solving the more important work of your application logic. It should also have the added advantage of having a much larger user community than your applications so that code will be well-tested and maintained.

Kristian Wijaya wrote:
-When trying to make a login form, why would using Struts 2 be actually advantageous?


A login form is probably a bad example as Struts builds upon the Servlet specification and uses the same security mechanism.
Any non-trivial form will require the same process: retrieve information to display as Java objects, convert those objects into HTML, validate user entries, convert HTTP request into objects and store information for future reference. Struts takes the bulk of that work out of your hands while also providing a plug-in architecture for you to intervene when necessary.

Kristian Wijaya wrote:
-Is there some feature in Java that can only be achieved using Struts 2?


Not that I'm aware of.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 2 Hello World - Having Trouble in Starting up
 
Similar Threads
Unable to load tag handler class "com.opensymphony.webwork.views.jsp.PropertyTag
JCaptcha and Struts
Can't get index.jsp to refer to hello.jsp
Caused by: java.lang.ClassNotFoundException: org.apache.jsp.form.XXHd_jsp
JSTL configuration problem in Eclipse