struts2 拦截器 获取请求中的参数~!怎么弄?送分题

sqz10200 2009-10-13 09:38:55
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,怎么获取啊···


大家帮帮忙了··
...全文
2031 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
leesoftware 2009-10-30
  • 打赏
  • 举报
回复
收分了
sqz10200 2009-10-13
  • 打赏
  • 举报
回复
我知道··

已经搞定了··
imasmallbird 2009-10-13
  • 打赏
  • 举报
回复
想要拦截方法应该让生成的拦截器 extends MethodFilterInterceptor
sqz10200 2009-10-13
  • 打赏
  • 举报
回复
	
<interceptor-ref name="reportForms" >
<param name="includeMethods">exportExcel</param>
<param name="excludeMethods">exportChartXML</param>
</interceptor-ref>


我在XML 里 配置了··这个属性但是不起作用啊···

只要走Action它就会走拦截器··

我只想让Action里的exportExcel这个方法··走拦截器··怎么弄啊·
sqz10200 2009-10-13
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 imasmallbird 的回复:]
我想在拦截器里获取Action里面的filename,怎么获取啊···


首先,你要清楚拦截器与Action的运行先后,拦截器是在通过了之后,才会到Action,如果你这个Action是在到这个拦截器之前的Action,那么这个属性要放在页面上,然后点击一个请求的时候再以参数的形式带过来

其次,你的东西本来就放在了请求中然后带到拦截器中,你的那种得到参数的方法已经可以了,是什么原因让你还想得到更好的方法呢??
[/Quote]

我只是想知道看看··有没有别的方法啊···只是想多个形式都试试···
sqz10200 2009-10-13
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 xiaozhangnima 的回复:]
引用 3 楼 sqz10200 的回复:
引用 1 楼 xiaozhangnima 的回复:
你要在action中把"filename"放在Map里


大哥

我的是前置拦截器···

要在进入Action之前做判断的··

这个跟你拦截器在XML配置位置有关系
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;
    }
}
[/Quote]



你要在action中把"filename"放在Map里


你的意思不就是让我把filename在Action里 往session里放 对吧


但是我现在连Action都不进去··你让我怎么放···

我现在不是要对session中的值进行判断··


我现在是要对 从页面穿过来的 时候对参数进行判断···

明白?

参数对··在进到Action里继续执行···否则 回去···

我不知道Struts2有没有,除了2楼我发的那种方法之外的···

其他的形式···
imasmallbird 2009-10-13
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 sqz10200 的回复:]
引用 1 楼 xiaozhangnima 的回复:
你要在action中把"filename"放在Map里




大哥

我的是前置拦截器···

要在进入Action之前做判断的··
[/Quote]

既然是放在之前,那你就在request中带过来,然后向你在2楼那样取就可以了呀~~
imasmallbird 2009-10-13
  • 打赏
  • 举报
回复
我想在拦截器里获取Action里面的filename,怎么获取啊···


首先,你要清楚拦截器与Action的运行先后,拦截器是在通过了之后,才会到Action,如果你这个Action是在到这个拦截器之前的Action,那么这个属性要放在页面上,然后点击一个请求的时候再以参数的形式带过来

其次,你的东西本来就放在了请求中然后带到拦截器中,你的那种得到参数的方法已经可以了,是什么原因让你还想得到更好的方法呢??
xiaozhangnima 2009-10-13
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 sqz10200 的回复:]
引用 1 楼 xiaozhangnima 的回复:
你要在action中把"filename"放在Map里




大哥

我的是前置拦截器···

要在进入Action之前做判断的··
[/Quote]
这个跟你拦截器在XML配置位置有关系
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;
}
}
sqz10200 2009-10-13
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 xiaozhangnima 的回复:]
你要在action中把"filename"放在Map里

[/Quote]


大哥

我的是前置拦截器···

要在进入Action之前做判断的··
sqz10200 2009-10-13
  • 打赏
  • 举报
回复
ActionContext actionContext = invocation.getInvocationContext();   
HttpServletRequest request= (HttpServletRequest) actionContext.get(StrutsStatics.HTTP_REQUEST);

System.out.println(request.getParameter("export.strDate"));
System.out.println(request.getParameter("export.nodeid"));



除了这种方式

还有没有别的方式啊··
xiaozhangnima 2009-10-13
  • 打赏
  • 举报
回复
你要在action中把"filename"放在Map里

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧