<!-- 判断登陆的过滤器 -->
<filter>
<filter-name>LoginFilter</filter-name>
<filter-class>
tools.LoginFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>public class LoginFilter implements Filter { protected FilterConfig filterConfig;
protected String encodingName;
protected boolean enable; public LoginFilter() {
encodingName = "UTF-8";
enable = false;
} // 初始化
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException { HttpServletRequest httprequest = (HttpServletRequest) request;
  HttpServletResponse httpresponse = (HttpServletResponse) response;
  HttpSession session = httprequest.getSession();
  ActingAdminUser user=new ActingAdminUser();
 
  RequestDispatcher dispatcher=request.getRequestDispatcher("login.jsp");
  try { //获得在session中所记录的user,该属性由登录部分的代码写入   
   user = (ActingAdminUser) session.getAttribute("user");
   if (user!=null||httprequest.getServletPath().startsWith("/adminUser.do")||httprequest.getServletPath().startsWith("/login.jsp") ) //验证成功,继续处理
   {
    chain.doFilter(request, response);
   } else //验证不成功,让用户登录。
   {
    dispatcher.forward(httprequest, httpresponse);     
    
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
} public void destroy() {
}
}<form action="adminUser.do?pare=login" name="loginform" method="post">
     <input type="text" name="adminUser.code" value="admin"/>
     <input type="password" name="adminUser.password" value="admin"/> 
     <input type="submit" value="登陆" >
    </form>
我的项目是ssh,struts1.2的,我在输入http://localhost:8080/51hiptActing/adminUser.do 会报异常
Request[/adminUser] does not contain handler parameter named 'pare'.  This may be caused by whitespace in the label text. 我的struts是以pare为变量传方法名的我点登陆按钮就能进adminUser的action,还有我打项目所有的xxxx.do都可以回到login.jsp没异常,但是xxxx.do?pare=随便
也会报错
总之就是想要一个变成一个好点的过滤器,错误也不停服务器的

解决方案 »

  1.   

    Request[/adminUser] does not contain handler parameter named 'pare'.  This may be caused by whitespace in the label text.
    这个异常往往是对DispatchAction 不熟悉造成,在用它的时候别忘记了在STRUTS-CONFIG中的<action>属性加parameter="pare",还有<html:form>和普通的<form>是有区别的,在用form提交表单的时候别忘记要家范围method="post",不然也会有错,还有在action.do/pare=XXXX这个中间不要有空格!过滤器好像没啥问题
      

  2.   

    你配置这个action的struts配置文件拿出来看看?
      

  3.   


    <struts-config>
      <form-beans >
        <form-bean name="actingForm" type="form.ActingForm" />  </form-beans>  <global-exceptions />
      <global-forwards />
      <action-mappings >
        <!-- 用户 -->
        <action path="/adminUser" type="action.AdminUserAction" name="actingForm" parameter="pare" >
        <forward name="loginok" path="/regedit.jsp"></forward>
        <forward name="loginerror" path="/login.jsp"></forward>
        <forward name="toUpdate" path="/updateAdmin.jsp"></forward>
        <forward name="userlist" path="/adminlist.jsp"></forward>
        <forward name="main" path="/main.jsp"></forward>
        </action>
        </action-mappings>
      <controller processorClass="org.springframework.web.struts.AutowiringRequestProcessor"></controller>
      <message-resources parameter="web.ApplicationResources" />
    </struts-config>
      

  4.   

    再发下你的action.AdminUserAction的代码好吗?
      

  5.   

    代码没问题,地址栏输入有问题
    你那么输入,意思是默认找excute()方法
    没有当然会出错
      

  6.   

    看上边代码没什么错误还是action的使用上有点问题。
      

  7.   

    楼主的问题问的有点不清楚,看了半天才好像有点明白你是什么意思了。先看看你的问题:
    我在输入http://localhost:8080/51hiptActing/adminUser.do 会报异常
    因为你的doFilter中有startsWith("/adminUser.do")这个条件。
    所以这个页面不做拦截。通过。但你这么请求的时候pare参数没有。struts1找不到对应的parameter就报错了。我点登陆按钮就能进adminUser的action
    同理,你点按钮的时候也不做拦截。但你的action中有pare参数,所以没问题。action="adminUser.do?pare=login" 我打项目所有的xxxx.do都可以回到login.jsp没异常
    除去你设的adminUser.do和login.jsp,其它的xxx.do都会被拦截。直接转页,不进struts1所以没异常但是xxxx.do?pare=随便 
    也会报错 
    只要不是adminUser.do应该不会出错,可能是你的pare=一个action中没有方法名了,总之就是想要一个变成一个好点的过滤器,错误也不停服务器的
    doFilter中不是有request参数吗。request.getParameter("pare")取出来做判断。为null或是action中不存在的方法就自己把它设成你需要走的默认方法。这样OK?
      

  8.   

    http://localhost:8080/51hiptActing/adminUser.do这种直接输入方法是有问题的,就像5楼的朋友说的哪样,他是直接去找他的execute方法,但是你在action里面应该是吧execute方法去掉了,所以它找不到,他需要你带参数去找方法名,然而你没有带上,所以就会报出错误。然而你说你点登陆的时候就能进入adminUser的action,因为你点击登陆提交的时候你带有参数传递"adminUser.do?pare=login”他调用的就是你action里面的login方法,这个肯定不会报错误。你输入其他XXX.do的时候也没有问题,但是xxxx.do?pare=随便也会报错,这种情况就像10楼的朋友说的哪样,这下子你应该明白了吧。