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?
Related
I'm learning about servlets and JSP and I try to make an app. The app is from this page
This is the structure of the app:
And I put all the JSP in WEB-INF:
When I try to run any jsp it's not working, I get this error: HTTP Status 404 – Not Found... Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
If I move the jsp in WebContent the app is working succesfully. But I want to keep the jsp in WEB-INF. What should I do? Thanks in advance!
Seems i got your problem. If you have servlet class write code to forward to jsp page like this. Because you have put your jsp page inside WEB-INF/view
request.getRequestDispatcher("/WEB-INF/view/homeView.jsp").forward(request, response);
I have an EJB with servlet project and JSP as front end pages.
I'm trying to deploy the project on a glassfish 4.0 server. Everything worked fine until now, when all my jquery and css files are overwritten with html of the current jsp page. I have no idea what is happening.
All the jquery and css files look ok in project folders.
See bellow print screen.
Anyone encountered this wired behaviour??
Overwritten jquery
Overwritten CSS
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.
I have multiple web applications defined in my tomcat. In case of any exception, I want to throw one jsp (done using SimpleMappingExceptionResolver tag of spring). When I put the jsps in the web-inf folder of the web applications, it works fine which is obvious.
But I want to put this jsp at a common place in tomcat such as ROOT library. But if I do this, tomcat is not able to find my jsp. Can somebody tell me if any changes in web.xml is required to make this happen or I should put this jsp somewhere else.
Thanks in advance.
What do you mean by 'picked up' or 'access'? You can put a jsp file on the tomcat ROOT application, and do a 302 redirect into it everytime you encounter exception.
For example place you all-apps generic exception page on webapps/ROOT/generic_exception.jsp, then on each of your apps, add this to the web.xml
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/myapp_error.jsp</location>
</error-page>
That should redirect request into myapp_error.jsp (inside myapp) if any uncaught exception surfaces. Then inside myapp_error.jsp, just perform html meta redirect to /generic_exception.jsp
However the drawback of this approach is you are redirected into different web-app, it's difficult / require extra work if you want to pass session attributes
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.