文件管理 · 2022年7月25日

struts2配置文件传参数|struts2 配置文件传参问题

1. 关于struts2的struts.xml中向action传参数的问题

你在getStudent用request取值,试试HttpServletRequest request=ServletActionContext.getRequest();request.getParament("dataID");

2. struts2配置文件依赖注入参数对应的action类的相应属性是null怎么办

问题就出在get方法中,struts2是基于依赖注入的,因此struts2内部已经提供了自动注入机制了,就不需要通过ServletActionContext.getServletContext().getRealPath获取所注入的值,将get方法改为public String getSavePath() throws Exception{ return savePath; }就OK了,望采纳!

3. 我现在用struts2进行项目开发,在action的配置文件中进行action之间的跳转时需要传递参数

<result name="XXXX" type="redirectAction"> <param name="actionName">要调用的action的名字</param> <param name="namespace">要调用的action的包名</param> </result>

4. struts2中xml的配置action使用通配符传递参数

strutx的来name上面使用通配符是可以的,但我们一自般很少这样用,因为作为一个与后台通信的跳转Action,我们必须保证他的唯一性,并且要与后台Action中的方法名对应。

至于传参,估计你说的形式是这样的:login.action?id="1234"&name="cc"。这种传参方法,需要将?后面的参数的名字指定,不然在后台Action类中就不知道把参数赋给谁了!

5. struts2中如何传值

Struts2传值有几种方式:1)URL parameter例如配置代码: <action name="login_*" class="com.my.action.LoginAction" method="{1}"> <result type="redirectAction" name="success">main?userName=${userName}&password=${password}</result> <result type="redirect" name="false">login</result> <result name="input">/pages/Login.jsp</result> </action>其中:main?userName=${userName}&password=${password}这一句是当调用Action SUCCESS时会把原Action中的username和password两个属性以url parameter形式传给main action当然,上面main action也可以这样写: <result name="success" type="redirectAction"> <param name="actionName">main</param> <param name="userName">${userName}</param> <param name="password">${password}</param> </result>2)request的attribute传值:例如,可以在一个action中使用attribute传值: HttpServletRequest request = ServletActionContext.getRequest(); request.setAttribute("userName", getUserName());当然,先要import page:import javax.servlet.http.HttpServletRequest;import org.apache.struts2.ServletActionContext;ServletActionContext有好些方法,可以得到pageContext、request、session、application等对象来使用。在Struts2 Action中需要调用Appcalition和Session,需要用到这个引用:import com.opensymphony.xwork2.ActionContext;调用方法如: ActionContext.getContext().getSession().put("username", getUsername()); ActionContext.getContext().getApplication().put("username", getUsername());如果需要在Action中调用request、response、pageContext,需要引用:import org.apache.struts2.ServletActionContext;调用方法:ServletActionContext.getPageContext() …ServletActionContext.getRequest() …ServletActionContext.getResponse() …

6. struts2.3.3 如何传递参数到Action

从页面传:直接form表单提交或者自己拼接参数?aa=a&bb=b配置文件传 struts的配置文件中<action>标签下可以用 <param name="hello">world</param>标签

7. struts2中文参数如何传递到action中

在struts.xml配置文件加上(struts2.2以上):<constant name="struts.118n.encoding" value="utf-8" />

8. struts2请求路径如何带参数

你在页面写请求路径的时候直接在action后面加?params=…如果有多个的话用&连接

9. struts2 配置文件传参问题

chain是用来调用外包的action的,你调错了没有? 放请求不行啊?

10. Struts2中页面传的参数在Action文件中怎么取

进行 set get 后,可以直接取。 public class NewDocCateAction extends ActionSupport { // 日志 private static Log log = LogFactory.getLog(NewDocCateAction.class); // Action类公用私有变量,用来做页面导航标志 private static String forward = null; private DocCateDao ; private String cateparentid; // 父节点 private String catetarget; // target private String catecode; // 文件类别编号 private String catename; // 文件类别名称 private String catehelpcode; // 助记码 private String cateremark; // 备注 public String execute() throws Exception { try { DocCate doccate = new DocCate(); doccate.setCateparentid(cateparentid); doccate.setCatecode(catecode); doccate.setCatename(catename); doccate.setCatehelpcode(catehelpcode); doccate.setCateremark(cateremark); doccate.setCatetarget("netmainFrame"); .save(doccate); forward = "success"; } catch (Exception ex) { //ex.printStackTrace(); log.info(ex.toString()); forward = "input"; } return forward; } public static String getForward() { return forward; } public static void setForward(String forward) { NewDocCateAction.forward = forward; } public DocCateDao getDao() { return ; } public void setDao(DocCateDao ) { this. = ; } public String getCateparentid() { return cateparentid; } public void setCateparentid(String cateparentid) { this.cateparentid = cateparentid; } public String getCatetarget() { return catetarget; } public void setCatetarget(String catetarget) { this.catetarget = catetarget; } public String getCatecode() { return catecode; } public void setCatecode(String catecode) { this.catecode = catecode; } public String getCatename() { return catename; } public void setCatename(String catename) { this.catename = catename; } public String getCatehelpcode() { return catehelpcode; } public void setCatehelpcode(String catehelpcode) { this.catehelpcode = catehelpcode; } public String getCateremark() { return cateremark; } public void setCateremark(String cateremark) { this.cateremark = cateremark; }}