我在localhost:8084 / ues /中提供我的应用程序。我想将所有请求从localhost:8084 / ues / *重定向到localhost:8084 / ues / index.jsp。我怎么能这样做?
答案 0 :(得分:0)
在部署描述符中定义过滤器,如
<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
答案 1 :(得分:0)
在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
}
}
}