Reputation: 3736
I have a webapp with webcontext rootname "testProject". I tried to use the web.xml
and configure the welcome-file:
<welcome-file-list>
<welcome-file>/jspFiles/index.html</welcome-file>
</welcome-file-list>
This works on tomcat, but not on jetty:
Tomcat 7.0:
localhost:8080/testProject/
localhost:8080/testProject/jspFiles/index.html
Jetty 9.0:
localhost:8080/testProject/
localhost:8080/testProject/jspFiles/index.html
My webcontent folder looks like this;
Webcontent
|
+ jspFiles/index.html
|
+ META-INF
|
+ WEBINF
|
+ web.xml
Do I need to configure something extra to make this work on jetty?
Upvotes: 2
Views: 3367
Reputation: 341
What I have found is the Eclipse.jsp wizard puts the jsp very close to where it should be but both Eclipse embedded jetty or Eclipse producing a .war are putting the .jsp where the server can not find it. In both case I have right clicked on the jsp, selected MOVE, then placed it in either in the webapp folder for embedded or the WebContent folder for a Java EE WAR. I do this for every new jsp I code in both cases.
It is really hard to show but I will try. Wrong way for Eclipse running embedded jetty:
src/main/webapp (folder)
+>css (package)
+>images (package)
+>WEB-INF (folder)
++>lib (folder)
web.xml
my.jsp
ohmy.jsp
ohmygod.jsp
Here web.xml is in the correct place but I never figured out what place. my.jsp is not found, ever.
Now if you use the move function to move my.jsp into src/main/webapp it ends up looking like this and my.jsp is found and everything works.
src/main/webapp (folder)
+>css (package)
+>images (package)
+>WEB-INF (folder)
++>lib (folder)
web.xml
my.jsp
ohmy.jsp
ohmygod.jsp
As I said I still do not know where web.xml "is" because it is with the lib folder but not in it. The .jsp are in the webapp folder (they really are) where the documentation says they should be and everything works. It looks a little different for a .war but the problem and resolution are the same. As a worst case just move the .jsp(s) around (or in your case the welcome files) until the server finds them if these instructions do not make sense to you.
I have what I need for the moment but when (if) I figure out the welcome files I will come back and update this.
Upvotes: 0
Reputation: 49515
The values found in <welcome-file>
are simply appended to the incoming request in an attempt to find the resource the http client is asking for.
Entries with a '/'
just complicate things (especially at the beginning, which is considered non-normalized)
Take for example, the following example:
Webapp deployed to '/foo'
You have 1 <welcome-file>jsps/index.jsp</welcome-file> set
Your webapp contents are:
/WEB-INF/web.xml
/jsps/index.jsp
/css/main.css
/js/jquery.js
/bar/list.jsp
Lets take a few scenarios.
/foo
{webapp-base}/
exist as file resource? nope{webapp-base}/jsps/index.jsp
exist as file resource? yes, process it./foo/bar
{webapp-base}/bar
exist as file resource? nope.{webapp-base}/bar/jsps/index.jsp
exist as file resource? nope.The "as file resource" part is overly simplified, on purpose, as the search for a file resource can be any of the following locations (this is not the official search order, see the servlet spec for the official order)
/WEB-INF/classes
/WEB-INF/resources/
/META-INF/resources/
in a jar file in /WEB-INF/lib/
And then, the JSP implementations themselves add the ability to find content in other locations.
Mainly because your request for a file ending in *.jsp
means that the JspServlet (usually mapped at the jsp
servlet name) will be asked for content too.
Some implementations will even use the incoming request.getPathInfo()
against any content in /WEB-INF/
(This is done to allow the jsps to exist in say /WEB-INF/my.jsp
for the JspServlet to use (when compiling) and serve the response, but also get the standard servlet spec security of /WEB-INF/
and never have the jsp source itself be served without being processed.
Upvotes: 1