1. 程式人生 > >網頁放在WEB-INF下面怎樣釋出訪問

網頁放在WEB-INF下面怎樣釋出訪問

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