How can lunch JSP project on Tomcat? I copy WebContent folder to webapp folder of Apache but it can’t find my jsp page, but if I change jsp to jsf (index.jsf) works fine. How can I solve this problem?
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Graph</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<description>
This parameter tells MyFaces if javascript code should be allowed in
the rendered HTML output.
If javascript is allowed, command_link anchors will have javascript code
that submits the corresponding form.
If javascript is not allowed, the state saving info and nested parameters
will be added as url parameters.
Default is 'true'</description>
<param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>
If true, rendered HTML code will be formatted, so that it is 'human-readable'
i.e. additional line separators and whitespace will be written, that do not
influence the HTML code.
Default is 'true'</description>
<param-name>org.apache.myfaces.PRETTY_HTML</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<description>
If true, a javascript function will be rendered that is able to restore the
former vertical scroll on every request. Convenient feature if you have pages
with long lists and you do not want the browser page to always jump to the top
if you trigger a link or button action that stays on the same page.
Default is 'false'
</description>
<param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
<param-value>true</param-value>
</context-param>
<servlet>
<servlet-name>faces</servlet-name>
<servlet-class>org.apache.myfaces.webapp.MyFacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>UploadServlet</servlet-name>
<servlet-class>controler.UploadServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>faces</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>faces</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>UploadServlet</servlet-name>
<url-pattern>/Upload</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
</web-app>
Error:
type Status report
message /Graph/index.jsp
description The requested resource
(/Graph/index.jsp) is not available.
That’s not a problem. That’s expected behaviour. You’re just misunderstanding how the basic Servlet API works. You have configured the JSF-standard
FacesServletto listen on URLs matching/faces/*and you have configured Apache MyFaces specificMyFacesServletto listen on URls matching*.jsfand*.faces.To get JSF to run, you have to open the page in browser by an URL which matches the mapping of the
FacesServlet. Given the fact that you’ve anindex.jspfile and that your context path isGraphand that you have configured two JSF servlets on three different URL patterns, you can open the JSP by the following URLs:FacesServlet)MyFacesServlet)MyFacesServlet)Said that, your configuration is unnecessarily overcomplicated. Get rid of the
MyFacesServletentry and all of its associated URL mappings (with the servlet name offaces). Just stick to the standardFacesServletand use its mapping instead, or alter it instead. I personally recommend using*.jsf.Then you can just open the page by http://localhost:8080/Graph/index.jsf.
Unrelated to the concrete problem, your
welcome-filewon’t work that way. Tomcat would give a HTTP 404 error on that (page/resource not found). You need to specifyindex.jsfaswelcome-fileand supply a concrete but emptyindex.jsffile in the same folder as yourindex.jsp. This way Tomcat will be fooled that the file exist and show the page by just calling http://localhost:8080/Graph.If your concern is that it is possible to open JSF pages by their
*.jspextension which would result in aRuntimeException: FacesContext not foundand you have actually no one JSP file which is to be served plain vanilla, then you can restrict direct access to JSP files by the following security constraint inweb.xml:(in JSF 2.0 this is by the way not needed anymore, with the default view technology Facelets it’s possible to map the
FacesServleton just*.xhtml, which is the same as the default extension of Facelets files)