jsp:include causes Servtlet exception app engine - java

After a lot of debugging I found that every time I include jsp files like:
<jsp:include page="header.jsp">
when I try do do a HTTP request like: /whatever/request I get the following exception:
javax.servlet.ServletException: File "/whatever/header.jsp" not found
The same exception will happen if I try any path instead of /test above for instance /test/test/request or anything.
When I removed all the directives everything is fine. How do I workaround this.

It looks for jsp relative to context path, in your example it looks for jsp stored in /whatever/header.jsp and it is not there, you should access jsp files by writing their full project's path, otherwise it will look for those jsp in the exact folder you are referring to in your url, if it shows error in folder /list/London, and you include jsp like
<jsp:include page="some.jsp"/>
Then it will look for that file in /list/London/, but if you write
<jsp:include page="/some.jsp"/>
It will look for it in your project's root, meaning under /

Related

How to use <c:url> in <c:import> on Java?

I'm trying to import a JSP using c:import and c:url, but it tells me it couldn't find the file. I tryed using a link to see if it opens the file, and it works fine. So, I suppose the path is correct, but it isnt't working.
My code is like this:
<c:url value="/cabecalho.jsp" var="cabecalho" />
<c:import value="${cabecalho}"></c:import> //page don't open
link //to test the path
If I use <c:url value="cabecalho.jsp" /> it works fine!
What must be happening?
c:url gives You absolute path from internet like http://www.somehost.com . c:import wants relative path to jsp on server.

JSP file Include in from Jar file

I have two different project In first Project have all js,ftl java files and I included jsp file also in:
Webcontent/test.jsp
META-INF/resources/test.jsp
META-INF/test.jsp
When I exported this jar file in another project, I'm unable to call this jsp file.
Tried Following way:
<jsp:include page="/test.jsp"></jsp:include>
<jsp:include page="/test.jar!/resources/test.jsp"></jsp>
but it's still showing error while accessing this path in jsp.

Getting error running struts2 helloworld program

I m new in Struts2. Creating a hello world program using struts. When I run it got first screen where i put my input but when click on submit button giving following error.
Source of this helloworld example: http://www.tutorialspoint.com/struts_2/index.htm
HTTP Status 404 - /HelloWorldStruts2/hello
type Status report
message /HelloWorldStruts2/hello
description The requested resource (/HelloWorldStruts2/hello) is not available.
Apache Tomcat/6.0.29
Suggest what is the issue?
Got the solution.
In index.jsp there was <form> tag. When I changed it to <s:form> its working fine.
Or change from
<form action="hello">
to
<form action="hello.action">
This is what worked for me, specific to the question. Tomcat 8 was used:
Make sure you have created the classes folder under WebContent\WEB-INF.
In that create the logging.properties file and add the following content to it. (It doesn't matter if the file jumps on its own to Java Resources > Libraries) :-
org.apache.catalina.core.ContainerBase.[Catalina].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].handlers = \ java.util.logging.ConsoleHandler
Then in the location of Tomcat's webapps folder delete your HelloWorldStruts2.war file.
Now follow the site's instructions to Export your project to a new HelloWorldStruts2.war file (remember to overwrite the existing .war file with the same name if it's there).
Again, deploy this file by copying it to your Tomcat directory's webapps folder.
In the browser, go to http://localhost:8080/HelloWorldStruts2/index.jsp again, though I'm not sure it will work for sure this time.
But this time, watch the Tomcat server application's verbose output. You will get some kind of exception like this (leave out Warnings for now):
30-Mar-2014 17:39:29.273 SEVERE [localhost-startStop-7] org.apache.catalina.core.StandardContext.filterStart Exception starting filter struts2 java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:213)
at org.apache.struts2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:102)
...
Seeing this, what I did immediately was copy the commons-lang3-x.y.z.jar to the WebContent\WEB-INF\lib folder, and then exported and deployed the project again.
This time, again the page wasn't showing, so I watched the logs and found out that Tomcat did not explicitly clear the contents of the webapps\HelloWorldStruts2 folder.
After deleting both HelloWorldStruts2 and HelloWorldStruts2.war and refreshing the index.jsp page in the browser, my project did work fine!

Linking Files And Directory Structuring

I'm working on a web project using java/ jsp/ servlets/ html/ css in eclipse tomcat, where everything is in the WebContent folder.
In my jsp files... When I try to include other jsp files (using a link like "/fileName.jsp" in jsp include directive) I can do that successfully.
But When I try to include image files (using a link like "/fileName.jpg" in the <img src=""> tag) nothing happens.
Nothing happens because instead of looking in the WebContent folder for image file it looks in the tomcat home directory, i.e.
Instead of looking at "http ://localhost:port/projectName/..." it looks at "http: //localhost:port/..."
Why does it look at the wrong location only with <img src=""> tags but not in <%# /> tag.
A workaround for this is that I start giving absolute paths "/projectName/..." However doing this means I'm hardcoding project name everywhere. This is what I do not want.
Don't include binary content in an ascii output. Why not just use the img tag? If you need to do something to produce a jpeg, I would use a Servlet.
Because the jsp-Links in the website are getting processed and the image links not. Either change the image path or develop an filter that changes the images'links.
Yes Templar, that could have been a way to solve my problem.
However, I simply changed the Context Root of my project from "Project Name" to "/" in Eclipse. This solved my problem.

JSP Template tutorial. How do I use a jar file

I am trying to follow the tutorial for JSP Templates at:
http://java.sun.com/developer/technicalArticles/javaserverpages/jsp_templates/
I am struggling to understand the <%# taglib uri='/WEB-INF/tlds/template.tld' prefix='template' %> tag.
What is the template.tld file, where does this come from?
I have tried to download the Resourses file of source code but this just contains a src.jar file. How do I use this? I can't even open the file!?! How do I see the source code example?
It's in the jstl.jar. You need standard.jar and jstl.jar in your WEB-INF/lib for JSTL.
You can get what you need here:
http://tomcat.apache.org/taglibs/
Download the standard tag library and all its JARs; put them in your WEB-INF/lib directory.
A uri, a uniform resource identifier is not necessarily pointing to any existing resource. It is an identifier, compare with url which is a uniform resource locator which helps you locate something. In many XML contexts for instance, it simply declares a namespace.
Sometimes the uri does however point to a real resource that you can read to get more information.
In this case you are declaring a namespace template to use in your jsp code (such as <template:dosomething/>) - the uri matches a uri declaration for whatever is implementing your tag functionality and can be found inside a jar (jstl.jar or standard.jar, can't remember which).

Categories

Resources