我在项目中的web.xml中配制 
<welcome-file-list>
<welcome-file>productshow.action?type=index</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
打算每次最初开始在浏览器中输入 http://localhost:8088/mshop/时,让页面跳转到productshow.action?type=index的action,但是第一次是进去了,如果第一次后再输入http://localhost:8088/mshop/却一直只跳转到index.jsp页面,也就是加载不上应该有的数据,所以就想使用拦截器,每次输入http://localhost:8088/mshop/时,都让其跳转到带有productshow.action?type=index所处理后的数据的页面,请问这样一个拦截器应该怎么写呢?谢谢,ip地址最好不固定

解决方案 »

  1.   

    webwork的拦截器在web.xml中配置,什么时候被调用呢?也就是什么时候起到拦截的作用呢?
      

  2.   

    你的welcome-file配得感觉好别扭只弄个index.jsp,index.jsp直接跳转到productshow.action?type=index不就行了
      

  3.   

    web.xml文件配置<welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
    index.jsp直接跳转到你的action
      

  4.   

    怎么两个welcome-file?去掉后面那么试试
      

  5.   

    下面那个不能删除,删除后出现选择页面的列表:让选择index2.jap,detail.jsp等,说明上一个没有找到,所以才找的第二个。。,这里应该用拦截器处理一下吧?不太知道怎么处理!!
      

  6.   

    web.xml只是在tomcat启动时才加载一次,所以可以进入第一个action,但是以后tomcat启动着,在输入http://localhost:8088/mshop/,则只是进入index.jsp了。。,拦截器应该在整个tomcat启动后,每次请求是都做拦截,但是我写了一个,结果死循环了:如下:
    package org.liky.filter;import java.io.IOException;import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;public class InitFilter implements Filter { public void destroy() { } public void doFilter(ServletRequest req, ServletResponse resp,
    FilterChain chain) throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    // System.out.println("request.getRemoteAddr()="+request.getRemoteAddr());
    if (request.getSession().getServletContext()
    .getAttribute("initcatalog") == null) {
    if (request.getRequestURI().indexOf("login") == -1 && request.getRequestURI().indexOf("login") == -1) {
    ((HttpServletResponse)resp).sendRedirect("/mshop/productshow.action?type=index");
    System.out.println("-----到了if语句---"+request.getRemoteAddr());
    }
    }
    else{
    String StrUrl="http://"+request.getRemoteAddr()+":8088/mshop";
    String StrUrl2="http://localhost:8088/mshop";
    if(StrUrl.equals(request.getRequestURI()) || StrUrl2.equals(request.getRequestURI())){
    ((HttpServletResponse)resp).sendRedirect("/mshop/productshow.action?type=index");
    System.out.println("应该跳转request.getRequestURI().equals(strURL)=");
    }
    }
    chain.doFilter(req, resp);
    } public void init(FilterConfig arg0) throws ServletException {
    }}
    ((HttpServletResponse)resp).sendRedirect("/mshop/productshow.action?type=index");
    System.out.println("应该跳转request.getRequestURI().equals(strURL)=");

    }
    chain.doFilter(req, resp);
    } public void init(FilterConfig arg0) throws ServletException {
    }}当tomcat启动后,第一个进入action,后来再输入http://localhost:8088/shop/还是只是进入index.jsp页面,请指点!!谢谢