gc00001
gc00001
2012-12-14 16:52
浏览 339
已采纳

struts2自定义拦截器怎么进不去

一个破拦截器搞了半天没发现哪里出问题了就是进不去自定义的拦截器里,下面贴代码:
struts.xml
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">

<!-- 拦截器 -->

<interceptor-ref name="myoneInterceptor"/>


<!--系统所用的拦截器栈名 -->


MyJsp.jsp


java代码(在com.niit.action包里)
Act类
package com.niit.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ApplicationAware;
import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;
import org.apache.struts2.util.ServletContextAware;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class Act extends ActionSupport {

public String login(){
return "input";
}

}

MyOneInterceptor类
package com.niit.action;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class MyOneInterceptor extends AbstractInterceptor{

public String intercept(ActionInvocation actionInvocation) throws Exception {
    // TODO Auto-generated method stub
    System.out.println("进入我的拦截器");

    Object action = actionInvocation.getAction();
    System.out.println("请求的对象名:" + action.getClass().getName());

    return actionInvocation.invoke(); //让url继续执行
}

}

index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


        <input type="submit" value="提交"/> 

    </s:form> 


MyJsp.jsp
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

index.jsp


struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

5条回答 默认 最新

  • jinnianshilongnian
    jinnianshilongnian 2012-12-14 17:00
    已采纳

    1、

    你开动态方法调用了吗?

    2、有错误吗?
    3、如果不行clean下服务器试试

    点赞 评论
  • iteye_5246
    iteye_5246 2012-12-14 16:59

    这种demo犯不着纠结,直接百度个用了
    [url]http://www.cnblogs.com/lihuiyy/archive/2012/03/29/2423569.html[/url]

    点赞 评论
  • henghanan
    henghanan 2012-12-14 17:14

    动态方法调用默认是开启的

    之所以访问不到action的方法,是因为你没有在struts.xml配置访问action的后缀

    点赞 评论
  • dohkoos
    dohkoos 2012-12-15 19:16

    把public class MyOneInterceptor extends AbstractInterceptor{
    改成
    public class MyOneInterceptor implements Interceptor{
    试试

    点赞 评论
  • costtian
    costtian 2015-03-23 09:59

    大哥你这个问题是怎么解决的?

    点赞 评论

相关推荐