0

我在 localhost:8084/ues/ 中提供我的应用程序。我想将所有请求从 localhost:8084/ues/* 重定向到 localhost:8084/ues/index.jsp。我该怎么做?

4

2 回答 2

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

于 2013-02-28T06:36:15.867 回答
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
                }
}
}
于 2013-02-28T06:37:21.737 回答