ONLY14
2016-06-01 02:30
package com.zsq.action; import javax.servlet.http.HttpServletRequest; import com.opensymphony.xwork2.ActionSupport; public class HelloWorldAction extends ActionSupport { private HttpServletRequest request; public String add() { request.setAttribute("path", "update"); return "add"; } public String update() { return "update"; } @Override public String execute() throws Exception { // TODO Auto-generated method stub System.out.println("执行action"); return SUCCESS; } }
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <package name="defult" namespace="/" extends="struts-default"> <default-action-ref name="index"></default-action-ref> <action name="index"> <result>/error.jsp</result> </action> <action name="*_*" method="{2}" class="com.zsq.action.{1}Action"> <result>/result.jsp</result> <result name="add"> <param name="location">/${#request.path}.jsp</param> </result> <result name="update">/{2}.jsp</result> <result name="error">/error.jsp</result> </action> <action name="LoginAction" method="login" class="com.zsq.action.LoginAction"> <result>/success.jsp</result> <result name="input">/login.jsp</result> </action> </package> </struts>
package com.zsq.action; import javax.servlet.http.HttpServletRequest; import com.opensymphony.xwork2.ActionSupport; public class HelloWorldAction extends ActionSupport { private HttpServletRequest request; public String add() { request.setAttribute("path", "update"); return "add"; } public String update() { return "update"; } @Override public String execute() throws Exception { // TODO Auto-generated method stub System.out.println("执行action"); return SUCCESS; } }
你这里的request要初始化,你试试,我估计你是报了空指针异常的。
private HttpServletRequest request=ServletActionContext.getRequest();
但是怎么初始化啊,老师也没说
我也是报了空指针异常,原来要初始化啊!
<action name="*_*" method="{2}" lass="com.zsq.action.{1}Action">
<result>/result.jsp</result>
<result name="add">
这段代码错啦!
Struts2入门
95062 学习 · 456 问题
相似问题