急!!!电子商务网站的商品信息更改问题
想设置一个商品信息的修改页面,但是一直提示空指针异常。这是jsp代码:
<%@page import="java.util.Iterator"%> <!-- need -->
<%@page import="org.util.Pager"%> <!-- need -->
<%@page import="java.util.List"%> <!-- need -->
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%> <!-- need -->
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!-- need -->
<html>
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta charset="utf-8">
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<title>菜点信息修改</title>
<link rel="stylesheet" href="css/style.css" media="screen">
<link rel="stylesheet" href="css/home-page.css" media="screen">
<link rel="stylesheet" href="css/ribbon-guideline.css" media="screen">
<link rel="stylesheet" href="css/Catalog-products.page.css" media="screen">
<link rel="stylesheet" href="css/Catalog-products-list.page.css" media="screen">
<link rel="stylesheet" href="css/Products-comparison.page.css" media="screen">
<script src="js/jquery.carouFredSel-6.1.0-packed.js"></script>
<script src="js/jquery.selectbox.min.js"></script>
<script src="js/slides.min.jquery.js"></script>
<script src="js/plugins.js"></script>
</head>
<body class="no-js Shopping-cart-page">
<div id="container">
<jsp:include page="head2.jsp"></jsp:include>
<form action="altdish.action" method="post" enctype="multipart/form-data">
<div id="wrapper">
<article class="pr-list">
<header class="entry-header">
<h1 class="entry-title"><strong>菜点信息修改</strong></h1>
</header>
<ul class="content-ul-list">
<li class="new">
<div></div>
<div class="img-list">
<a><img src="img/dish/${requestScope.linkdish.picture}" width="225" height="199"></a>
</div>
<div class="content-list">
<div><strong>菜名</strong></div>
<input type="text" name="dish.dishname" class="focusField" value="${requestScope.linkdish.dishname}" onclick="focus();select()">
<div><strong>菜点介绍</strong></div>
<textarea cols="40" rows="9" name="dish.descripation" onclick="focus();select()">${requestScope.linkdish.descripation}</textarea>
</div>
<div class="list-block-3">
<div class="list-price">
<div><input type="text" name="dish.price" class="focusField" value="${requestScope.linkdish.price}" onclick="focus();select()"></div>
<div><input type="text" name="dish.price0" nclass="focusField" value="${requestScope.linkdish.price0}" onclick="focus();select()"></div>
<div></div>
<div style="margin-left:30px;"><input value="1" type="checkbox" name="dish.classic" check="checked">
经典
<input type="checkbox" value="1" name="dish.sale">
折扣</div>
<div style="margin-left:30px;"><input value="1" type="checkbox" name="dish.new_">
新品
<input type="checkbox" name="dish.index">
主页</div>
<div style="margin-left:30px; margin-top:5px;">
<label><strong>所属类别</strong></label>
<select class="sort-by" name="type">
<option value="1">风味主食</option>
<option value="2">精品菜式</option>
<option value="3">健康菜式</option>
<option value="4">滋补汤羹</option>
<option value="5">饭后甜品</option>
<option value="6">特色饮料</option>
</select>
</div>
</div>
<div style="margin-left:140px; margin-top:15px;">
<input type="submit" value="确认修改"/>
</div>
</div>
</li>
</ul>
<div class="pr-pager2">
</div>
</article>
</div><!-- /#wrapper -->
</form>
</div><!-- /#container -->
<footer id="footer" role="contentinfo" class="sk-clearfix clearfix">
<div class="footer-in sk-width"><!--/.widget-area-->
<div class="footer-bottom clearfix">
<div class="widget-area">
<ul class="xoxo">
<li class="block widget">
<div class="widget-content"></div>
</li>
<li class="block widget">
<div class="widget-content">
</div>
</li>
<li class="block widget">
<div class="widget-content">
</div>
</li>
</ul>
</div><!--/.widget-area-->
</div>
</div><!--/.footer-bottom-->
</footer>
</body>
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
</html>
这是被action调用的方法
public String altdish() throws Exception {
Dish currdish=(Dish) ActionContext.getContext().getSession().get("linkdish");
System.out.println("-----------"+dish);
currdish.setDishname(dish.getDishname());
currdish.setPrice(dish.getPrice());
currdish.setPrice0(dish.getPrice0());
currdish.setNew_(dish.getNew_());
currdish.setClassic(dish.getClassic());
currdish.setSale(dish.getSale());
currdish.setCatalogid(dish.getCatalogid());
currdish.setDescripation(dish.getDescripation());
currdish.setNewindex(dish.getNewindex());
if(dishService.updateDish(currdish)){//修改成功
return SUCCESS;
}else
{
return ERROR;
}
}
而且输出dish也不为空的。
--------------------编程问答-------------------- 忘了贴错误提示了
--------------------编程问答-------------------- type Exception report
message
description The server encountered an internal error that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
org.action.DishAction.altdish(DishAction.java:258)
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:314)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:142)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:166)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395) --------------------编程问答-------------------- 258行是这一行
currdish.setDishname(dish.getDishname());
补充:Java , Java EE