当前位置: 代码迷 >> J2EE >> J2EE怎么为其他目录设置默认页面
  详细解决方案

J2EE怎么为其他目录设置默认页面

热度:150   发布时间:2016-04-22 03:09:12.0
J2EE怎样为其他目录设置默认页面
我是tomcat服务器,如果我的项目名称为:Item,则我在浏览器中输入“http://localhost:8080/Item”就会自动跳转到默认的index.jsp页面(就是web.xml中设置的<welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list>),但是如果我输入“http://localhost:8080/Item/jsp”就会把这个目录中所有的页面显示出来,请问我如何为这个二级目录也设置一个默认的页面呢?谢谢

------解决方案--------------------
参考 http://topic.csdn.net/t/20030606/09/1882588.html

<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
------解决方案--------------------
Java code
    <servlet>    <servlet-name>jspDefault</servlet-name>    <servlet-class>com.xxx.JspDefault</servlet-class>    </servlet>    <servlet-mapping>    <servlet-name>jspDefault</servlet-name>    <url-pattern>/jsp</url-pattern>    </servlet-mapping>---------------------public class JspDefault extends HttpServlet{    protected void doGet(HttpServletRequest request, HttpServletResponse response)        throws ServletException      , IOException {        String toUrl = request.getContextPath()+"/jsp/myIndex.jsp";        response.sendRedirect(toUrl);    }}
------解决方案--------------------
整上一个过滤器 
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletResponse res = (HttpServletResponse)response;
HttpServletRequest req = (HttpServletRequest)request;
//判断一下 请求字符串 为http://localhost:8080/Item/jsp
//req.getRequestDispatcher("/login.do?method=loginIn").forward(req, res);
//跳到你指定的页面上 上面可以参考
chain.doFilter(request, response);
}
------解决方案--------------------
req.getRequestDispatcher("/login.do?method=loginIn").forward(req, res); 

chain.doFilter(request, response);
  相关解决方案