File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes How can I disable the call to jsp file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How can I disable the call to jsp file?" Watch "How can I disable the call to jsp file?" New topic
Author

How can I disable the call to jsp file?

Stephen Lee
Ranch Hand

Joined: Dec 11, 2001
Posts: 74
In web.xml, it is allowed to disable the invoker (that means call to
servlet file directly will be directed to other page). How can I do the same
for the jsp page? For example, there's a page login.jsp. The following is
part of the web.xml:
<servlet>
<servlet-name>loginjsp</servlet-name>
<jsp-file>/login.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>loginjsp</servlet-name>
<url-pattern>/loginPage</url-pattern>
</servlet-mapping>
I expect that the page can be accessed by calling http://localhost/loginPage
only. I don't want people can access the page by http://localhost/login.jsp
So I have added the following details in the web.xml:
<servlet>
<servlet-name>redirectorservlet</servlet-name>
<servlet-class>RedirectorServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>redirectorservlet</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
The RedirectorServlet is used for redirect the page to another page.
However, in JBuilder, when I start the tomcat server, it generates the
following contents in the web.xml and delete my above mapping :
<servlet>
<servlet-name>debugjsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>jspCompilerPlugin</param-name>
<param-value>com.borland.jbuilder.webserverglue.tomcat.jsp.JasperSunJavaComp
iler</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>debugjsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
Then how can I disable the call to jsp file directly?
Thanks!
Stephen
ersin eser
Ranch Hand

Joined: Feb 22, 2001
Posts: 1072
Using tokens .
Also remember that the files under WEB-INF folder can not be accessed directly
Stephen Lee
Ranch Hand

Joined: Dec 11, 2001
Posts: 74
That means placing the jsp file in WEB-INF. Therefore, the jsp pages cannot be viewed by typing the path http://localhost/*.jsp.
The page can be accessed by the use of RequestDispatcher from a servlet program or using custom URL set in web.xml. However, it is required to use <jsp:include page="xxx.jsp" /> to include another jsp. However, the jsp is placed in the WEB-INF also, so ServletException is thrown. How can I include the jsp file successfully in this way? i have tried to use absolute path, however, it is still unsuccessful. What should I do? Thanks
Stephen
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I disable the call to jsp file?