private User user; private String inputPath; private String filename; public InputStream getInputStream() throws Exception {
return ServletActionContext.getServletContext().getResourceAsStream(
this.getInputPath());
} /**
* 导出Excel
*
* @return
*/
public String exportExcel() {
}
↑是Action里面的代码··
public class SiteInterceptor extends AbstractInterceptor { @Override
public String intercept(ActionInvocation invocation) throws Exception {
Map<String, Object> parameters = invocation.getInvocationContext()
.getParameters();
Stringed = parameters.get("filename").toString();
System.out.println(ed);
Map session = invocation.getInvocationContext().getSession();
String role = (String) session.get("filename");
System.out.println("AuthorizationInterceptor.username:\t" + role);
return invocation.invoke();
}}↑这个是拦截器里的···
我想在拦截器里获取Action里面的filename,怎么获取啊···我想在拦截器里获取Action里面的filename,怎么获取啊···我想在拦截器里获取Action里面的filename,怎么获取啊···
大家帮帮忙了··
return ServletActionContext.getServletContext().getResourceAsStream(
this.getInputPath());
} /**
* 导出Excel
*
* @return
*/
public String exportExcel() {
}
↑是Action里面的代码··
public class SiteInterceptor extends AbstractInterceptor { @Override
public String intercept(ActionInvocation invocation) throws Exception {
Map<String, Object> parameters = invocation.getInvocationContext()
.getParameters();
Stringed = parameters.get("filename").toString();
System.out.println(ed);
Map session = invocation.getInvocationContext().getSession();
String role = (String) session.get("filename");
System.out.println("AuthorizationInterceptor.username:\t" + role);
return invocation.invoke();
}}↑这个是拦截器里的···
我想在拦截器里获取Action里面的filename,怎么获取啊···我想在拦截器里获取Action里面的filename,怎么获取啊···我想在拦截器里获取Action里面的filename,怎么获取啊···
大家帮帮忙了··
HttpServletRequest request= (HttpServletRequest) actionContext.get(StrutsStatics.HTTP_REQUEST);
System.out.println(request.getParameter("export.strDate"));
System.out.println(request.getParameter("export.nodeid"));
除了这种方式
】
还有没有别的方式啊··
import java.util.Map;import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
public class AuthorizationInterceptor extends AbstractInterceptor {
@Override
public String intercept(ActionInvocation ai) throws Exception {
ActionContext ctx = ai.getInvocationContext();
Map session = ctx.getSession();
//取出名为user的Session属性
String user = (String)session.get("userinfo");
//如果没有登陆,或者登陆所用的用户名不是scott,都返回重新登陆
if (user != null || "".equals(user) )
{
return ai.invoke();
}
//没有登陆,将服务器提示设置成一个HttpServletRequest属性
ctx.put("tip" , "您还没有登陆,请输入正确用户名和密码登陆");
//直接返回login的逻辑视图
return Action.LOGIN;
}
}
首先,你要清楚拦截器与Action的运行先后,拦截器是在通过了之后,才会到Action,如果你这个Action是在到这个拦截器之前的Action,那么这个属性要放在页面上,然后点击一个请求的时候再以参数的形式带过来其次,你的东西本来就放在了请求中然后带到拦截器中,你的那种得到参数的方法已经可以了,是什么原因让你还想得到更好的方法呢??
既然是放在之前,那你就在request中带过来,然后向你在2楼那样取就可以了呀~~
你要在action中把"filename"放在Map里你的意思不就是让我把filename在Action里 往session里放 对吧
但是我现在连Action都不进去··你让我怎么放···我现在不是要对session中的值进行判断··
我现在是要对 从页面穿过来的 时候对参数进行判断···明白?参数对··在进到Action里继续执行···否则 回去···我不知道Struts2有没有,除了2楼我发的那种方法之外的···其他的形式···
<interceptor-ref name="reportForms" >
<param name="includeMethods">exportExcel</param>
<param name="excludeMethods">exportChartXML</param>
</interceptor-ref>
我在XML 里 配置了··这个属性但是不起作用啊···只要走Action它就会走拦截器··我只想让Action里的exportExcel这个方法··走拦截器··怎么弄啊·