网页放在WEB-INF下面怎样发布访问

来源:互联网 发布:北京理工大学网络登录 编辑:程序博客网 时间:2024/06/13 00:57

web project网页放在WEB-INF下面受保护,不能直接访问,有下面三种方式:

假设要发布的网页为a.jsp,建表单form。

1、在web.xml中,将默认<welcome-file>index.jsp</welcome-file>改成<welcome-file>./WEB-INF/view/a.jsp</welcome-file>,其他注释:

   <!-- <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>  -->
    <welcome-file>./WEB-INF/view/a.jsp</welcome-file> 


访问方式为:http://localhost:8080/demo/

2、建servlet,jump.java,doGet下写方法

RequestDispatcher rd = request.getRequestDispatcher("./WEB-INF/view/a.jsp");
rd.forward(request, response);


在web.xml中给URL取访问名,jump:

    <servlet-name>jump</servlet-name>
    <servlet-class>database.jump</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>jump</servlet-name>
    <url-pattern>/jump</url-pattern>
  </servlet-mapping>


访问方法:http://localhost:8080/demo/jump

3、在web.xml中自建<servlet-mapping>


在a.jsp中修改from action的获取方式:

<form action="<%=request.getContextPath() %>/doinsert" method="post">

访问方式:访问方法:http://localhost:8080/demo/doinsert.jsp


0 0