I have a webapp in a main JSP file that contains a JSP file between the other in the beta. I think preventing the file from being directly accessible, and only want to allow direct access to the main index page. In addition, I do not want users to be able to get images directly from my webapp. How can I reject those requests with Tomcat? I want to forward all of the request to my main page. After will have to implement one of the ways For example: < / P> Add the web. Xml to the following: edit Everything you need to know about which page is being requested
package package; Import javax.servlet. *; Import javax.servlet.http.HttpServletRequest; Import javax.servlet.http.HttpServletResponse; Public class FilterImplementation applies filter {Public Zero Init (FilterConfig filterConfig) Throw ServletException {...} Public Zero doFilter (ServletRequest request, ServletResponse response, FilterChain series) throws IOException, ServletException {// If you detected an invalid request , Throwing an exception or returning the chain without making a call. Chain.doFilter (request, response); } Public Zero Destroy () {...}}
& lt; Filter & gt; & Lt; Filter-name & gt; MyFilter & lt; / Filter-name & gt; & Lt; Filter range & gt; Package.FilterImplementation & lt; / Filter range & gt; & Lt; / Filter & gt; & Lt; Filter-mapping & gt; & Lt; Filter-name & gt; MyFilter & lt; / Filter-name & gt; & Lt; URL pattern & gt; / * & Lt; / URL pattern & gt; & Lt; / Filter-mapping & gt;
request Is in the parameter . Parameter type but it will almost always be one so you can do the following:
if requested (HttpServletRequest instance) {HttpServletRequest hrequest = (HttpServletRequest) request; String uri = greenquest.getrequestionary (); // You should just be able to use this string uri = hrequest.getRequestURL (); // otherwise there are more areas in depth}
Comments
Post a Comment