Home  >  Article  >  Web Front-end  >  Detailed explanation of how to directly access JSP pages in the WEB-INF directory

Detailed explanation of how to directly access JSP pages in the WEB-INF directory

韦小宝
韦小宝Original
2018-01-04 10:19:082368browse

This article mainly introduces relevant information on how to directly access the JSP page in the WEB-INF directory. Friends who are interested in JSP can refer to the detailed explanation below to access directly. Methods for the JSP page in the WEB-INF directory

The JSP page in the WEB-INF directory cannot be directly accessed through the address bar, and the files in the WEB-INF directory cannot be directly accessed. Access is mainly for security reasons. Of course, if security is not a concern, you can directly put the JSP page in the webapp directory outside WEB-INF, so that you can also access it directly. Let’s talk about how to directly access the jsp page in the WEB-INF directory

It can be accessed through forwarding. I use Controller for forwarding, as follows:


package com.sogou.baike.controller; 
 
import org.apache.log4j.Logger; 
import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.servlet.ModelAndView; 
 
/** 
 * Created by denglinjie on 2016/6/3. 
 */ 
@Controller 
public class CompareController { 
 
  private static Logger logger = Logger.getLogger(CompareController.class); 
 
  @RequestMapping(value = "/api/compare", produces = "text/html; charset=utf-8") 
  public ModelAndView getCompareHomePage() { 
    ModelAndView view = new ModelAndView("compare"); 
    return view; 
  } 
 
}


In this way, when the page is requested, you can enter


http://10.10.10.10:30005/api/compare

## in the address bar.

#This request is processed by the above Controller and jumps to the compare.jsp page through ModelAndView. Of course, if you want to use ModelAndView, you need to configure the


view parser in the Spring configuration file. My configuration is as follows:



<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> 
    <property name="prefix" value="/WEB-INF/vm/" /> 
    <property name="suffix" value=".jsp" /> 
  </bean>


My compare.jsp page is placed in the /WEB-INF/vm directory, so that after entering the above address in the address bar, you can jump to the WEB-INF directory through the controller jsp page

Thank you for reading, I hope it can help everyone, thank you for your support of this site!

Related recommendations:

How to redirect a web page in jsp

How to test a JSP page outside the container

JSP basic knowledge points summary

The above is the detailed content of Detailed explanation of how to directly access JSP pages in the WEB-INF directory. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn