Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

strange error with respect to web.xml file

 
Anil Deshpande
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am preparing for SCWCD, I am implementing the struts application as shown in the Heas First Servlets and JSP.


form.jsp looks like:




web.xml looks like




the ActionForm looks line:



and the BeerSelectionForm




the code for web.xml is:



the struts-config.xml is



When I execute and access the form.jsp, it gives me the error


org.apache.jasper.JasperException: The absolute uri: http://jakarta.apache.org/struts/tags-html cannot be resolved in either web.xml or the jar files deployed with this application
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:51)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:116)
org.apache.jasper.compiler.TagLibraryInfoImpl.generateTLDLocation(TagLibraryInfoImpl.java:317)
org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:148)
org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:435)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:504)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1568)
org.apache.jasper.compiler.Parser.parse(Parser.java:132)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:212)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:101)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:156)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:296)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:265)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:302)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)



What is the problem.?
 
Sushil Jamsandekar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your web.xml try putting following elements inside <servlet></servlet>



Also you need to download the taglib : struts-html.tld and make its refarance in web.xml like


Am not sure if we can referance the tld directly with the uri you have provided.
 
Ankit Garg
Sheriff
Posts: 9520
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no need to map the tld in the web.xml. The container (or at least most containers) automatically search for tlds inside jar files inside the lib folder, so if the struts library files are in the lib folder, then the container will automatically map the URI to the tld...
 
Anil Deshpande
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changed the form.jsp

Now the code looks like this



But there seems to be problem with the struts-config.xml

It is givig me the error


is the problem with configuring FontController Servlet?
 
Salil Vverma
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Anil,

While trying the code, I discovered 5 errors that I had to resolve to get the code working. Those errors are as follows -

1- As I can see from your struts-config.xml you are using struts 1.3. The first mistake was in your form.jsp where you gave wrong uri="http://jakarta.apache.org/struts/tags-html". The correct one is -uri="http://struts.apache.org/tags-html"

2- In struts-config.xml , to represent action mapping you used opening tag <action-mapping> which is wrong, it should be <action-mappings>.

3- You gave the type in action as com.example.web.BeerSelection while your action class is BeerSelectionAction.

4- In form.jsp while submitting you selection action as "/select/SelectBeer.do" while there is no mapping in struts-config.xml for "/select/SelectBeer". I believe, you should have made only "/SelectBeer" as type in struts-config.xml.

5- In web.xml you had given servlet init parameter at completely wrong place. This comes under servlet tag

I corrected all those error at my end. Now it is working perfectly fine here. The corresponding code files are as attached below -

Form.jsp


Struts-config.xml




Web.xml



result.jsp



BeerSelectionAction.java



BeerSelectionForm .java



I hope, this would solve all your doubts and would give you a working example.
 
Anil Deshpande
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the comprehensive reply. I have not yet checked the code to verify it. But I am so happy with this replay I couldn't stop myself from replaying as a token of appreciation.

As soon as I will get time I will verify he code and respond with certain clarifications.

Thanks a lot
 
Anil Deshpande
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did execute the code. And thanks once again. Did help me to clarify the mistakes.
 
Anil Deshpande
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Major problem, The code executes only when I am connected to the internet. If I am offline and start the tomcat it gives me this error



This is strange. Why should it be dependent on whether I am online or offline. I had executed Struts one year back. But it had executed even without I being connected to the internet.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic