struts2提供的接口ParameterAware怎么使用,哪里能查到具体用法,或者大侠们给个例子。
答案:1 悬赏:60 手机版
解决时间 2021-02-17 22:32
- 提问者网友:献世佛
- 2021-02-17 14:02
如题。提供文档或者例子都可以。
最佳答案
- 五星知识达人网友:三千妖杀
- 2021-02-17 14:58
ParameterAware 是一接口,只提供了一个方法,如下:
void setParameters(Map parameters)
在别处给你找了个例子:
//重点:通过继承org.apache.struts2.interceptor包下的**Aware接口的set**注入
package com.teana.action;
import java.io.PrintWriter;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.interceptor.ApplicationAware;
import org.apache.struts2.interceptor.ParameterAware;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import com.opensymphony.xwork2.ActionSupport;
public class AwareAction extends ActionSupport implements ServletResponseAware,
ServletRequestAware, SessionAware, ApplicationAware, ParameterAware
{
private HttpServletResponse response;
private HttpServletRequest request;
private Map session;
private Map application;
private Map parameters;
@Override
public String execute() throws Exception
{
PrintWriter out = response.getWriter();
out.write(parameters.get("name"));
out.write("========================");
out.write((String)request.getAttribute("name"));
out.write(session.toString());
out.write(application.toString());
//
return SUCCESS;
}
public void setServletResponse(HttpServletResponse response)
{
this.response = response;
}
public void setServletRequest(HttpServletRequest request)
{
this.request = request;
}
@SuppressWarnings("unchecked")
public void setSession(Map session)
{
this.session = session;
}
@SuppressWarnings("unchecked")
public void setApplication(Map application)
{
this.application = application;
}
@SuppressWarnings("unchecked")
//其实就是个注入,没别的,就这样用
public void setParameters(Map parameters)
{
this.parameters = parameters;
}
}
一般用的话,就是通过这个注入parameters 然后再获取参数用的
void setParameters(Map
在别处给你找了个例子:
//重点:通过继承org.apache.struts2.interceptor包下的**Aware接口的set**注入
package com.teana.action;
import java.io.PrintWriter;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.interceptor.ApplicationAware;
import org.apache.struts2.interceptor.ParameterAware;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import com.opensymphony.xwork2.ActionSupport;
public class AwareAction extends ActionSupport implements ServletResponseAware,
ServletRequestAware, SessionAware, ApplicationAware, ParameterAware
{
private HttpServletResponse response;
private HttpServletRequest request;
private Map
private Map
private Map
@Override
public String execute() throws Exception
{
PrintWriter out = response.getWriter();
out.write(parameters.get("name"));
out.write("========================");
out.write((String)request.getAttribute("name"));
out.write(session.toString());
out.write(application.toString());
//
return SUCCESS;
}
public void setServletResponse(HttpServletResponse response)
{
this.response = response;
}
public void setServletRequest(HttpServletRequest request)
{
this.request = request;
}
@SuppressWarnings("unchecked")
public void setSession(Map session)
{
this.session = session;
}
@SuppressWarnings("unchecked")
public void setApplication(Map application)
{
this.application = application;
}
@SuppressWarnings("unchecked")
//其实就是个注入,没别的,就这样用
public void setParameters(Map parameters)
{
this.parameters = parameters;
}
}
一般用的话,就是通过这个注入parameters 然后再获取参数用的
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯