0
我服務於我的應用程序在localhost:8084/ues /。我想將所有請求從localhost:8084/ues/*重定向到localhost:8084/ues/index.jsp。我該如何做到這一點?所有請求重定向特定的網址
我服務於我的應用程序在localhost:8084/ues /。我想將所有請求從localhost:8084/ues/*重定向到localhost:8084/ues/index.jsp。我該如何做到這一點?所有請求重定向特定的網址
重定向到所需的jsp中在你web.xml
具有下面的代碼,
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/ues/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>com.myPackage.redirectServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
public class redirectServletextends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response)
{
try
{
RequestDispatcher dispatcher = request.getRequestDispatcher("/pages/index.jsp");
dispatcher.forward(request, response);
}
catch(Exception e)
{
//catch your exceptions
}
}
}
定義一個過濾器在部署描述符等
<filter>
<filter-name>Filter-Name</filter-name>
<filter-class>Fully-Qualified-Class-Name</filter-class>
</filter>
<filter-mapping>
<filter-name>Filter-Name</filter-name>
<url-pattern>ues/*</url-pattern>
</filter-mapping>
並從Filter
首先給予時是指請求? – PSR 2013-02-28 06:30:09