如何访问WEB-INF下面的jsp文件

柔情只为你懂 2022-06-14 00:57 357阅读 0赞

在WEB-INF下面的文件是受保护的,如果我们直接在浏览器上输入地址去打开文件那是打开不了的。所以正常情况下img、css、js文件夹通常都不会放在WEB-INF下面的。
现在我们要去访问那怎么样才可以呢?使用跳转或者使用Struts2或者使用springmvc.
这里使用springmvc处理。
这里写图片描述

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation=" http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd ">
  3. <!-- 默认扫描的包路径,扫描Action -->
  4. <context:component-scan base-package="cn.yizhan.cc" />
  5. <!-- 解决@responsebody 中文乱码 -->
  6. <mvc:annotation-driven />
  7. <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
  8. <property name="prefix" value="/WEB-INF/"></property>
  9. <property name="suffix" value=".jsp"></property>
  10. </bean>
  11. </beans>
  12. package cn.yizhan.cc;
  13. import javax.servlet.http.HttpServletRequest;
  14. import javax.servlet.http.HttpServletResponse;
  15. import org.springframework.stereotype.Controller;
  16. import org.springframework.web.bind.annotation.RequestMapping;
  17. @Controller
  18. @RequestMapping("/demo")
  19. public class LoginController {
  20. @RequestMapping("/de.form")
  21. public String login(HttpServletRequest request,HttpServletResponse response){
  22. return "MyJsp";
  23. }
  24. @RequestMapping("/index.form")
  25. public String index(){
  26. return "index";
  27. }
  28. }
  29. <?xml version="1.0" encoding="UTF-8"?>
  30. <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  31. <display-name></display-name>
  32. <welcome-file-list>
  33. <welcome-file>/demo/index.form</welcome-file>
  34. </welcome-file-list>
  35. <servlet>
  36. <servlet-name>springmvc</servlet-name>
  37. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  38. <init-param>
  39. <param-name>contextConfigLocation</param-name>
  40. <param-value>classpath:spring-mvc.xml</param-value>
  41. </init-param>
  42. <load-on-startup>1</load-on-startup>
  43. </servlet>
  44. <servlet-mapping>
  45. <servlet-name>springmvc</servlet-name>
  46. <url-pattern>*.form</url-pattern>
  47. </servlet-mapping>
  48. </web-app>

其他方法都是类似的,这里不再多说。

发表评论

表情:
评论列表 (有 0 条评论,357人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Jsp访问JavaBean

          JavaBean是一种可重复使用且跨平台的软件组件。有两种一种带用户界面的,一种不带用户界面的主要负责表示业务数据和处理事务的JavaBean。JSP通常访问没带界

    相关 SpringMVC如何访问JSP

    1.场景还原     最近有些小伙伴问我:“星哥,在springmvc中怎么访问jsp,该怎么配置?”,这里笔者写下这篇博客详细的讲解下配置过程。 2.实现步骤