Struts2 与 webService

主要目标是让struts2不对webservice不进行拦截,因此写一个类来继续struts2的过滤器org.apache.struts2.dispatcher.FilterDispatcher

 

以下是自己写的过滤器类

 

<textarea cols="50" rows="15" name="code" class="java:collapse">/** * FilterDispetor.java * com.sword.actions * * Function: TODO * * ver date author * ────────────────────────────────── * 2010-7-2 lidl * * Copyright (c) 2010, TNT All Rights Reserved. */ package com.sword.actions; import java.io.IOException; import javax.servlet.FilterChain; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import org.apache.struts2.dispatcher.FilterDispatcher; /** * ClassName:FilterDispetor * Function: TODO ADD FUNCTION * Reason: TODO ADD REASON * * @author lidl * @version * @since Ver 1.1 * @Date 2010-7-2 下午12:58:37 * * @see */ @SuppressWarnings(&quot;deprecation&quot;) public class FilterDispetor extends FilterDispatcher { @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { // TODO Auto-generated method stub HttpServletRequest request=(HttpServletRequest) req; String uri=request.getRequestURI(); System.out.println(&quot;******************************:&quot;+uri); if(uri.indexOf(&quot;RemoteMachine&quot;)!=-1||uri.indexOf(&quot;/Servlet/&quot;)!=-1||uri.indexOf(&quot;Service&quot;)!=-1){ System.out.println(&quot;FilterDispetor.doFilter():true&quot;); chain.doFilter(req, res); }else{ super.doFilter(req, res, chain); } } } </textarea>

"RemoteMachine",为自己写的webservice名,"Servlet"为axis 要使用的

 

 

然后 修改 web.xml struts2 相关过分

<textarea cols="50" rows="15" name="code" class="java"> &lt;filter&gt; &lt;filter-name&gt;struts2&lt;/filter-name&gt; &lt;filter-class&gt; com.sword.actions.FilterDispetor &lt;/filter-class&gt; &lt;/filter&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;struts2&lt;/filter-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/filter-mapping&gt;</textarea>

 

 

你可能感兴趣的:(Struts2 与 webService)