struts2 提交表单 第一次提交null 后退页面在提交 可以赋值,怎么解决
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
com.pet.action.Pupetinfo.PupetinfoAction.add(PupetinfoAction.java:97)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
* 添加发布信息
* @return
* @throws IOException
*/
public String add() throws IOException{
//添加数据库
Customer customer = (Customer) session.get("customer");
pu.setCustomer(customer);
System.out.println("ffffffffffff");
totalinfo = pupetinfoDao.querybycustomerId(customer.getCustomerId());//每天发布的免费信息数量
bymoney = pupetinfoDao.querybymoneyinfo(customer.getCustomerId());//发布的收费信息数量
totalinfos = pupetinfoDao.querybycustomerIdDay(customer.getCustomerId());//总共发布的免费信息数量
if(pu.getInfotype().getInfotypeId()==1){ //如果是免费信息
if(totalinfo==0){ //如果每天发布的信息为0
//插入数据库
pupetinfoDao.addPupetinfo(pu);
//积分加5
customer.setIntegral_1(customer.getIntegral_1()+5);
//金额不变
customerDao.update(customer);//更新用户
Date date = new Date();
Calendar cal = new GregorianCalendar();
Calendar cal1 = new GregorianCalendar();
Calendar cal2 = new GregorianCalendar();
cal.setTime(date);
cal1.setTime(pu.getPupetinfoTime());
cal2.setTime(pu.getEndinfoTime());
Accountinfo acc = new Accountinfo();
acc.setConsume(pu.getInfotype().getInfotypeId());//信息等级
acc.setContext(pu.getTitle());//描述
acc.setCustomerId(customer.getCustomerId());//用户ID
acc.setDatesum(cal2.getTime().getDate()-cal1.getTime().getDate());//花费时间
acc.setGetintegral(5);//获得的积分
acc.setSurplusdb(customer.getCusmoney());//剩下的钱
acc.setSurplusintegral(customer.getIntegral_1());//剩下的积分
accountinfoDao.save(acc);
return "input";
}
msg="你已经发布了一条免费信息了";
session.put("msg", msg);
表单:
[解决办法]
你自己测试呗,你先测试dao,到没事,你在测试action的属性的get方法,看能不能拿到数据,不能的话,那你页面的值没有传递过来,不是你页面属性名字写错了,就是你的实体类的属性写错了,
我发现你宠物是个类,这里用了
宠物类型:<s:select name="petCategory.categoryId" theme="simple" list="petcatelist",
为什么
宠物价格:<s:textfield name="price" theme="simple" />
价格等没有用类的属性,而是直接用price
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html