i have made one project on E-Commerce using JSP technology of JEE, in that i have assigned a page named as home.jsp as a welcome page of my project. The page is located in the home_page folder of the Web Contents folder of my project. But when i run the project the contents of home.jsp don't get loaded in the browser page. I am attaching the code of the welcome page and the screenshot of the default welcome page in the browser apart from that i am also attaching the screenshot of the welcome page which is expected to come when the project executes.
<welcome-file-list>
<welcome-file>/home_page/home.jsp</welcome-file>
</welcome-file-list>
Try adding "/" at the end of the URL you're trying to access. It should fix it if you have servlets mapped in your web.xml.
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've had this simple jsp log-in form that used the css style sheet. It was working just fine until I included the web.xml file in my directory. Now the JSP file won't load the css files no matter what. I've tried changing the link address of the css in multiple different ways but with no luck.
I'm pretty positive that the web.xml file is the reason it's not loading because if I remove it, everything works again.
Here's my project structure:
Here's my login.jsp:
here's my web.xml:
Your web.xml includes /* in a security constraint, limiting access to all content of your application to those users with the role users. This means that, instead of serving your CSS file as requested to the browser, tomcat will redirect to the login.jsp as well (which is obviously an incorrect and not very stylish stylesheet)
We have a filter that redirects user to error.html, if the user is not authorized. Right now, we are keeping error.html page inside the WAR, but is there any way to make the html file public so that every war file can access this error page? It would be still better, if we make this html page as a jar and keep it in server/default/lib.
Here is the sample that is used in filter.
`reqDespacher = request.getRequestDispatcher("error.html")`
and the accessing url is
http://localhost/Context_root/error.html
Any help would be appreciated.
In JBoss5 or JBoss6, you can copy and then define this custom error.html inside the /deployer/jbossweb.deployer/web.xml of the server instance that you are running. This will require a reboot of the JBoss instance. Example for error code 404:
<error-page>
<error-code>404</error-code>
<location><relative_path_to_error_html_file_under_jbossweb.deployer_folder></location>
</error-page>
Secondly, instead of re-directing request by specifying a page manually like you are doing currently, you should use the <error-page> and <error-code> deployment directive to define custom error pages. See specify-the-default-error-page-in-web-xml-in-servlet for a detailed example on how to add error-code directives on web.xml.
For JBoss AS7 global error page configuration take a look at how-to-customize-jboss-as7-404-page .
i have a question:
I have a scenario that when user opens http://MYWEBSITE.com/abc/ , the user is directed to xyz.html page which is in abc subdirectory. I am using Java for web development. How can I do this in web.xml?
P.S. URL is http://MYWEBSITE.com/abc/ not http://MYWEBSITE.com/abc
you can use the welcome-file attribute in the web.xml
example:
<welcome-file>xyz.html</welcome-file>
This would get tomcat to look for a page matching the name (if found) and load it.
I have written a facelets web application using tomcat as a application server. My program has a foobar.xhtml and the URL to it is:
http://localhost:8080/Myapplication/foobar.faces
Can I change something in my application so that a link to:
http://localhost:8080/Myapplication/
..will actually render my application on http://localhost:8080/Myapplication/foobar.faces ?
Alternatively, could the http://localhost:8080/Myapplication/ be redirected to http://localhost:8080/Myapplication/foobar.faces ?
You would normally use the <welcome-file> entry in the web.xml for this. But unfortunately this doesn't work as expected on at least Tomcat when using fictive URL's which are to be passed through a servlet like a FacesServlet. Tomcat will scan for the physical file on the disk matching the exact name before forwarding. If it isn't present, then you will just face a default 404 error page.
Using /foobar.xhtml as <welcome-file> is also not going to work since that page requires to be parsed by the FacesServlet to get all the JSF stuff to work.
One of the ways to fix this is to place another real /foobar.faces file there next to the real /foobar.xhtml file. It doesn't need to be filled with code, it can be left empty. Just the presence of the physical file is enough for Tomcat to open the desired page as welcome page.
web.xml has a
<welcome-file-list>
<welcome-file>foobar.faces</welcome-file>
</welcome-file-list>
element where you can define the page to be opened.