日期:2014-05-17  浏览次数:20789 次

求教:关于struts2零配置的拦截器问题!
package com.still.action.admin;

import java.io.IOException;
import java.io.PrintWriter;

//import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.convention.annotation.Action;

import com.still.action.BaseAction;

@Action(value="staff")
public class StaffAdmin extends BaseAction{

/**

*/
private static final long serialVersionUID = 1L;
private final String encoding = "GBK";

public String getStaff(){
try {
StaffAdmin.responseOut(encoding, "登录中...", this.getResponse());
System.out.println(this.getRequest().getParameter("str"));
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

public Object getModel() {
return null;
}

public static void responseOut(String encoding, String data, HttpServletResponse response) {
response.setContentType("text/html; charset=" + encoding);
try {
PrintWriter pw = response.getWriter();
pw.print(data);
pw.close();
} catch (IOException e) {
e.printStackTrace();
}
}

}

注解方式实例化Action。

------解决方案--------------------
我也遇到了这样的问题
后来干脆用Filter了
------解决方案--------------------
web.xml里面配置了吗