according to netbeans e commerce tutorial. https://netbeans.org/kb/docs/javaee/ecommerce/page-views-controller.html#view there are 4 pages include header & footer placed in WEB-INF folder but they can access it via controllerservlet (RequestDispatcher).
i've googling and found a lot of questions about how to access/redirect to pages in WEB-INF folder but the result can't access pages(xhtml,jsp,etc) in WEB-INF folder.
my questions is
1. could i access pages in WEB-INF folder with RequestDispatcher (with JSF 2.X) ?
2. how to access pages in WEB-INF with JSF 2.X ?
A simple solution is to create a page that is outside WEB-INF. Let us call this page placeHolder.xhtml
If you know which page fragment you wish to show from within WEB-INF, then make it available via a bean. Let us say the following method returns the page that has to be included
#{mybean.pageToInclude}
Now, in the placeHolder.xhtml file, use the ui:include tag to include page that is present under WEB-INF
placeHolder.xhtml
...
<ui:inlucde src="#{mybean.pageToInclude}"/>
This way you can get code within WEB-INF to be made available in a page that is outside of it.
There are other techniques like writing a ResourceHandler to locate view resources under different locations that you can use too.
Hope that helps.
Related
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 are deeper into our project, and have set up a basic web application with eclipse. Whenever we attempt to run the server, we get a 404 error like the following
From my research, I have found I need some sort of web.xml file. Where should put this file what should be in it. How do I make it
Your problem is your trying to access a resource within the WEB-INF folder, that is not allowed and that is the reason you have this error, you must put the jsp under the WebContent folder or any folder under the WebContent folder.
The WEB-INF\classes contains the .class files for your Java classes and it's not a good place to put any resource.
Since the 3.0 specification for servlets the web deployment descriptor (web.xml) is optional.
I hope this could help you to fix your problem
Putting JSPs under WEB-INF makes them inaccessible unless you map them in WEB.XML The purpose of WEB-INF is to hide things because users cannot download or access anything under WEB-INF. You only put JSPs under WEB-INF if you don't want the user to be able to go there by its real name (i.e. http://localhost/app/whatever.jsp) but want to map it to some specific url (i.e. http://localhost/app/somename/)
Mapping a JSP that is under WEB-INF to a URL cane be done with this in the WEB.XML
<servlet>
<servlet-name>somename</servlet-name>
<jsp-file>/WEB-INF/whatever.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>somename</servlet-name>
<url-pattern>/somename/*</url-pattern>
</servlet-mapping>
Of course, if you need to map another URL to the JSP but don't feel the need to disallow the user from going there by its .jsp filename, you can use a URL Rewriting filter for that. In that case, there is no point in putting it under WEB-INF.
I'm maintaining a legacy Java servlet webapp ( nwp ). My goal is to learn Spring and gradually update the webapp to use Spring as much as possible.
The servlet webapp, nwp, now runs on WebLogic 9.2. It is packaged and deployed as nwp.war. Every HTTP Request gets submitted to a unique servlet, which process the request and prints out a web page/screen. Each servlet will read in various resource files from a remote location outside of nwp.war to use for headers, footers, etc.
Yes, it is primative, which is why I want to update it. It also made sense to have the "include files" in a remote location outside of the war as 3 applications use those files. However, as part of updating the nwp app I plan on consolidating the other two ( similarly primative ) apps into just the nwp. Eventually.
As a first step in converting this application to Spring I have rearranged the directory tree to have these subdirectories under the WEB-INF dir:
images
js
css
The servlet generated HTML references images as
"
My problem is that right now the servlet generated HTML can not find images in the WEB-INF/images directory inside of the nwp.war.
Right now, the nwp.war file contains a file called weblogic.xml to map the URLs for images to where they sit on the server:
<wls:virtual-directory-mapping>
<wls:local-path>/common/resources/images</wls:local-path>
<wls:url-pattern>/images/*</wls:url-pattern>
<wls:url-pattern>*.jpg</wls:url-pattern>
<wls:url-pattern>*.gif</wls:url-pattern>
</wls:virtual-directory-mapping>
I'm new to WebLogic and WebLogic 9.2.
I've tried changing that mapping in a number of was so that the servlet generated HTML will look for the pictures in the WEB-INF/images directory inside of the war.
Is this (servlet generated html finding images ) even possible or am I going to have to use the current system of getting images until I can convert the servlets into JSPs?
Thanks
Steve
The HTML won't be able to directly reference images inside the WEB-INF folder. This is for security. So you have 2 options:
Move the images so that they're directly under / rather than /WEB-INF/
Create another servlet to serve those images
If you decide to use a servlet, you can use ServletContext getResourceAsStream to access images from the /WEB-INF/images directory. For example:
servletContext.getResourceAsStream("/WEB-INF/images/test.jpg");
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.
My question is how to put all the JSP files in WEB-INF/JSP/ in the proper manner?
Is there any configuration for this as the structure I'm aware of is:
WEB-INF / JSP --> all jsp is reside in that folder
/ CLASSES -- all classes is reside that folder
/ LIB --> library file reside in that folder
How do I set this up properly according to the spec. Please help me with an answer for this.
You can put your JSP in
WEB-INF/jsp
folder and access that JSP using servlet.
Create login.jsp and then access that JSP using preloginservlet.java. This servlet redirects to login.jsp which is in the WEB-INF/jsp folder.
Its not a standard practice or valid as per the J2EE spec (I know using most of the java Web development frameworks like Struts, Spring MVC, Stripes you can do this). As per the spec, all our publicly accessibly pages should be out side of WEB-INF. But if you want the pages to be in web-inf, what you can do is to create a servlet along the lines of a controller servlet and forward the requests to jsp pages from your servlet and those pages can be in WEB-INF, and there is no special configuration that can be done to do this.
Create an intermediary JSP outside of WEB-INF that includes your JSP.
e.g.
your page inside of WEB-INF is ProjectName/WEB-INF/JSP/yourPage2.jsp
create a page ProjectName/yourPage1.jsp
Write below code in yourPage1.jsp
yourPage1.jsp
<%# include file="WEB-INF/JSP/yourPage2.jsp" %>
You create a jsp page out side WEB-INF folder and inside that jsp use jsp:forward as
In web.xml file use give outside jsp name in welcome file list.
It works for me...