Struts2 后台Action为什么接收不到表单提交上来的值?
如题,提交上来的值只有mr.MR_say是有的,其他的全部为null前台jsp代码:<formaction="mrsave"method="post"><table><t...
如题,提交上来的值只有mr.MR_say是有的,其他的全部为null
前台jsp代码:
<form action="mrsave" method="post">
<table>
<tr> <td><input name="mr.MR_name"></td></tr>
<tr> <td><input name="mr.MR_date"></td></tr>
<tr> <td><input name="mr.MR_say"></td></tr>
<tr> <td><input name="mr.MR_now"></td></tr>
<tr> <td><input name="mr.MR_befor"></td></tr>
<tr> <td><input name="mr.MR_allergy"></td></tr>
<tr><td colspan="2"><input type="submit"></td> </tr>
</table>
</form>
Action代码:
public class MrAction extends ActionSupport{
private Mr mr = new Mr();
private List<Mr> mrlist;
private MrService mrservice;
public List<Mr> getMrlist() {
return mrlist;
}
public void setMr(Mr mr) {
this.mr = mr;
}
public void setMrService(MrService mrservice) {
this.mrservice = mrservice;
}
public String save(){
System.out.println(mr);
mrservice.save(mr);
return SUCCESS;
}
}
bean代码:
public class Mr {
private Integer MR_no;
private String MR_name;
private Date MR_date;
private String MR_say;
private String MR_now;
private String MR_befor;
private String MR_allergy;
get和set方法都有了,是eclipse自动生成的。。
struts.xml
<action name="mr*" class="mrAction" method="{1}">
<result name="success">/jsp/Mr/list.jsp</result>
<result type="chain" name="finish">mrmrlist</result>
</action> 展开
前台jsp代码:
<form action="mrsave" method="post">
<table>
<tr> <td><input name="mr.MR_name"></td></tr>
<tr> <td><input name="mr.MR_date"></td></tr>
<tr> <td><input name="mr.MR_say"></td></tr>
<tr> <td><input name="mr.MR_now"></td></tr>
<tr> <td><input name="mr.MR_befor"></td></tr>
<tr> <td><input name="mr.MR_allergy"></td></tr>
<tr><td colspan="2"><input type="submit"></td> </tr>
</table>
</form>
Action代码:
public class MrAction extends ActionSupport{
private Mr mr = new Mr();
private List<Mr> mrlist;
private MrService mrservice;
public List<Mr> getMrlist() {
return mrlist;
}
public void setMr(Mr mr) {
this.mr = mr;
}
public void setMrService(MrService mrservice) {
this.mrservice = mrservice;
}
public String save(){
System.out.println(mr);
mrservice.save(mr);
return SUCCESS;
}
}
bean代码:
public class Mr {
private Integer MR_no;
private String MR_name;
private Date MR_date;
private String MR_say;
private String MR_now;
private String MR_befor;
private String MR_allergy;
get和set方法都有了,是eclipse自动生成的。。
struts.xml
<action name="mr*" class="mrAction" method="{1}">
<result name="success">/jsp/Mr/list.jsp</result>
<result type="chain" name="finish">mrmrlist</result>
</action> 展开
1个回答
展开全部
首先,struts2进行权限验证是用拦截器做的
一个简单的登录拦截器示例如下:
package com.zdf.interceptor;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.zdf.entity.Admin;
@SuppressWarnings("serial")
public class LoginInterceptor extends AbstractInterceptor{
@Override
public String intercept(ActionInvocation invocation) throws Exception {
// TODO Auto-generated method stub
Admin admin = (Admin)invocation.getInvocationContext().getSession().get("ADMIN");
if(admin!=null){
return invocation.invoke();
}else{
return Action.LOGIN;
}
}
}
一个简单的登录拦截器示例如下:
package com.zdf.interceptor;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.zdf.entity.Admin;
@SuppressWarnings("serial")
public class LoginInterceptor extends AbstractInterceptor{
@Override
public String intercept(ActionInvocation invocation) throws Exception {
// TODO Auto-generated method stub
Admin admin = (Admin)invocation.getInvocationContext().getSession().get("ADMIN");
if(admin!=null){
return invocation.invoke();
}else{
return Action.LOGIN;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询