• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How can I disable the call to jsp file?

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1072
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using tokens .
Also remember that the files under WEB-INF folder can not be accessed directly
 
Stephen Lee
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
You got style baby! More than this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic