iteye_13428
2009-06-07 01:25
浏览 342
已采纳

关于struts2.1.6 中使用<s:url >

之前使用struts2.0.11.1的时候,使用 标签时,会在后面生成一段;jsessionid=xxx;在网上看了一些解决方法;

例如:

修改core/src/main/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.java中的getMapping()方法;
......

但是2.1.6版本中,对这个问题已经做了处理.但是在使用时,在浏览器第一次加载的时候仍然含有;jsessionid=xxx;

请高人给个解决方法..

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • iteye_17762 2009-06-07 10:07
    已采纳

    加一个过滤器代码如下:

    package com.yunfei.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;
    import javax.servlet.http.HttpServletResponseWrapper;
    import javax.servlet.http.HttpSession;

    @SuppressWarnings("deprecation")
    public class DisableUrlSessionFilter implements Filter
    {

    /** *//**
     * Filters requests to disable URL-based session identifiers. 
     */
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
    {
        // skip non-http requests
        if (!(request instanceof HttpServletRequest))
        {
            chain.doFilter(request, response);
            return;
        }
    
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        HttpServletResponse httpResponse = (HttpServletResponse) response;
    
        // clear session if session id in URL
        if (httpRequest.isRequestedSessionIdFromURL())
        {
            HttpSession session = httpRequest.getSession();
            if (session != null) session.invalidate();
        }
    
        // wrap response to remove URL encoding
        HttpServletResponseWrapper wrappedResponse = new HttpServletResponseWrapper(httpResponse)
        {
            @Override
            public String encodeRedirectUrl(String url) { return url; }
    
            @Override
            public String encodeRedirectURL(String url) { return url; }
    
            @Override
            public String encodeUrl(String url) { return url; }
    
            @Override
            public String encodeURL(String url) { return url; }
        };
    
        // process next request in chain
        chain.doFilter(request, wrappedResponse);
    }
    
    /** *//**
     * Unused.
     */
    public void init(FilterConfig config) throws ServletException {}
    
    /** *//**
     * Unused.
     */
    public void destroy() {}
    

    }

    在web.xml中加入filter的配置,如下:


    DisableUrlSessionFilter

    com.yunfei.filter.DisableUrlSessionFilter

    <filter-mapping>
        <filter-name>DisableUrlSessionFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • wanghaolovezlq 2009-06-08 13:57

    jsessionid这个参数也就是用于url重写的,保留应该没什么问题,
    万一用户把cookie禁用后,也只能用这种url方式

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题