I have a quick question and wonder if anyone has come across this issue before?
I am trying to read a file from my classpath into a .jsp with spring but I keep getting a 404 even when the url is correct.
eg
/var/lib/tomcat7/webapps/ROOT/WEB-INF/classes/file/MyProcess.bpmn
The file is available in the browser from the above url but not through the .jsp in the Spring Framework where a 404 (Not Found)is returned.
Has anyone come across this problem before?
You have to move your file out of the WEB-INF directory I think because it won't be accessible from your jsp page.
This link should be useful
What is WEB-INF used for in a Java EE web application?
Related
I am building a servlet app to run on tomcat server. However when i was not able to update the jsp page using:
request.setAttribute("operation", "op_name");
request.getRequestDispatcher("\WEB-INF\index.jsp").forward(request, response);
404 index.jsp not found comes.
I think that servlet and web elements like jsp are in different paths that's why it is going wrong. So do i need to make another project using maven structure like having src\main\java etc. or this structure is also fine? Also how to update the index.jsp using this structure?
Not sure if it possible or not
Once a WebApp is running, is it possible to add a new JSP to the Webcontent folder, and assuming you know the name of newly added JSP make a requst for this new JSP?
Edit: Adding more details
We have a Java Batch application that will generate JSP files with embeded Java Scriplets e.g."<% Person.getName() %>". We want to be able to Run these JSP from within the web container to populate the javacode.
The only problem is that these JSP files are generated externally from the webapplication and we cannont restart the webapp everytime a new JSP is produced.
As a WebApp is running AFTER you deploy the project in the server, any change made while the WebApp is running won't affect the project until you deploy the project again.
I believe it's possible, but the question is too broad to give a meaningful answer.
One example of such behavior, is running Apache Tomcat server in debug mode in Eclipse, but that's a very special case.
Background
I'm working on a project for school. The goal is to create a learning website in the end. I've been creating my website locally and testing it going great so far, so I dediced to place it on the server to test it out there (deploy .war file). And as soon as I did that the whole website seems to not work.
Problem
The problem is that as soon as I try to click on any of my links that go through servlets, I get an error from tomcat saying that the requested resource is not available (http status 404). Which is sort of weird because it does work locally.
What have I tried
The first thing I noticed was that going to the server .war file is going to a snapshot url first (in my case: http://145.92.6.85:8080/PDL-1.0-SNAPSHOT/) instead of just landing on the index.jsp page right away (which happens locally) so my first thought was that it was using a whole different way to access the files I was looking for. Again strange because locally everything is working fine (using tomcat as well). I looked inside my project and tried to access the files I was looking for using the map structure, and this seemed to work. So instead of using the servlet I specified on the web.xml it's just ignoring it.
So then I decided it probaply can't find my web.xml file. I did a little searching online and found that it should be placed inside the map WEB-INF. Currently web.xml was sitting in META-INF, so placed it in WEB-INF, but to no avail. The pages I'm looking for still can't be found. I also read that some people said the classes for the projects (which I assume to be my servlets?) need to be placed inside a classes directory inside the WEB-INF folder. I decided not to do this, because currently I've got them all set up in different packages (Source Packages -> controllers/models etc.). And that seemed a lot more logical to me, and besides it's working locally so why would this not work on the server?
As far as I can tell my web.xml is set up correctly, but I'll show some code to indicate what the problem is.
Code
This is the URL I'm trying to follow (inside a navigation bar) (follows: http://145.92.6.85:8080/PDL/inlog)
<li>
Log In
</li>
this is the web.xml
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>controllers.login</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
The inlog.java file (inside Source Packages->controllers or PDL/src/main/java/controllers)
#Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
RequestDispatcher rd = request.getRequestDispatcher("/pages/inlog.jsp");
rd.forward(request, response);
}
This is where it breaks because it could not be found.
Finally
Whilst writing this question I do feel as if my URL's and stuff are maybe a little bit too changing and perhaps should be more dynamic than the current static ones (since the server enviroment is different I guess). Could anyone give me some tips as how to make the urls more dynamic, so they would work locally and on the server straight away (something like the PHP equivalent of $_SERVER['SERVER_NAME'] and the like? Any help would be greatly appreciated! Though I feel that the urls im redirecting to are the problem I just don't know how to solve this.
What is the name of the war file? Is it PDL-1.0-SNAPSHOT.war? Did you try accessing
"www.ip or domain name/PDL-1.0-SNAPSHOT/"?
If your war file has the version name, then you will have to edit the Tomcat configuration file to map the war file name, to the context root.
Please see http://tomcat.apache.org/tomcat-6.0-doc/config/context.html for more information, if you are using Tomcat 6.
OK, so you're messing the structure of the webapplication.
I do not know how you deploy it to the local server, but if you pack it as a war, you should follow simple rules. example of a valid structure
Application is moved by Tomcat5.0.
There will be an error if servlets-default.jar is contained in the application:
HTTP Status 404 - Servlet default is not available
However, when deleting servlets-default.jar out of application, it moved normally.
What does servlets-default.jar do?
Thank you nowaq!
Thank you Piotr Nowicki!
I'm user874235.
need more info, where did you get servlets-default.jar from?
⇒Sorry.This Application is very old.
It is not understood where servlets-default.jar was obtained.
However, I think that it probably obtained out of Tomcat.
(Incidentally servlets-default.jar’s size is 19K.)
he jar contains just a couple of files. The most important one is DefaultServlet.class.
⇒It seems that it is used in application, extending DefaultServlet.class when it checks.
The jar contains just a couple of files. The most important one is DefaultServlet.class. DefaultServlet is the default resource-serving servlet for most web applications, used to serve static resources such as HTML pages and images.
Take a look at the source files and they will tell you all.
I have a tomcat - spring mvc - jsp application.
I have discovered that a page called page.jsp is not found (404). But if I called page2.jsp then it just works fine.
Is it a bug or is it written somewhere in the spec that you can't call a jsp file page?
(BTW, I called it page because it is a part of the system that allows admins to administer pages. I.e. it is a name I really wanted - although I will readily switch to what works)
404 means 404, jsp is simply not there. This is tomcat, so go to webapps directory, and look into directory your war is unpacked into. Look for your JSPs.
Possible reasons for 404:
File is not there. Failed to package it
File is there, but called PAGE.JSP. URLs after domain name are case-sensitive.
Some funny filter installed in Tomcat that really prohibits page.jsp from being accessed. Unlikely.
Check your spring configuration file for URL mapping or there may be a wrong call to page.jsp from a controller.