添加菜品后跳转页面不行啊?出现500,怎么解决?

添加菜品后跳转页面不行啊?出现500,怎么解决?

http://img1.sycdn.imooc.com//climg/5d05b3760001f7fb10570543.jpg

package com.imooc.food;
public class Food {
 private String id;
 private String foodName;
 private String taste;
 private String path;
 private String price;
 private String describe;
 public Food() {
  
 }
 public Food(String id, String foodName, String taste, String path, String price, String describe) {
  super();
  this.id = id;
  this.foodName = foodName;
  this.taste = taste;
  this.path = path;
  this.price = price;
  this.describe = describe;
 }
 public String getId() {
  return id;
 }
 public void setId(String id) {
  this.id = id;
 }
 public String getFoodName() {
  return foodName;
 }
 public void setFoodName(String foodName) {
  this.foodName = foodName;
 }
 public String getTaste() {
  return taste;
 }
 public void setTaste(String taste) {
  this.taste = taste;
 }
 public String getPath() {
  return path;
 }
 public void setPath(String path) {
  this.path = path;
 }
 public String getPrice() {
  return price;
 }
 public void setPrice(String price) {
  this.price = price;
 }
 public String getDescribe() {
  return describe;
 }
 public void setDescribe(String describe) {
  this.describe = describe;
 }
 @Override
 public String toString() {
  return "Food [id=" + id + ", foodName=" + foodName + ", taste=" + taste + ", path=" + path + ", price=" + price
    + ", describe=" + describe + ", toString()=" + super.toString() + "]";
 }
 
 
}
package com.imooc.food;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class FoodDaoImpl {
 private static final List<Food> db=new ArrayList<Food>();
 private String msgString;
 public static List<Food> getDb(){
  return db;
 }
 
 public String getMsgString() {
  return msgString;
 }
 public void setMsgString(String msgString) {
  this.msgString = msgString;
 }

    //添加菜品
 public void addFood(Food food) {
  db.add(food);
 }
 //查询所有菜品信息
 public List<Food> getAllFood(){
  if(db.isEmpty()) {
   System.out.println("菜单是空的");
   return null;
  }else {
   Iterator it=db.iterator();
   return db;
  }
  
  
 }
 //根据菜品名称查询菜品信息
 public Food getFoodByName(String foodName) {
  Food food=new Food();
  for(int i=0;i<db.size();i++) {
   if(db.get(i).getFoodName().equals(foodName)) {
    food=db.get(i);
    break;
   }
  }
  return food;
  
 }
 //根据菜品id查询菜品信息
 public Food getFoodById(String id) {
  Food food=new Food();
  for(int i=0;i<db.size();i++) {
   if(db.get(i).getId().equals(id)) {
    food=db.get(i);
    break;
   }
  }
  return food;
  
 }
 //菜品修改
 public void updateFood(Food newFood) {
  for(int i=0;i<db.size();i++) {
   if(db.get(i).getId().equals(newFood.getId())) {
    db.remove(i);
    db.add(i, newFood);
    System.out.println("菜品已更新完成!");
    break;
   }
  }
 }
 //根据菜品ID进行删除
 public void deleteFoodById(String id) {
  if(db.isEmpty()) {
   System.out.println("菜品是空的");
   return;
  }else {
   for(int i=0;i<db.size();i++) {
    if(db.get(i).getId().equals(id)) {
     db.remove(i);
     break;
    }
   }
  }
 }
}
package com.imooc.servlet;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import com.imooc.food.Food;
import com.imooc.food.FoodDaoImpl;
import com.imooc.utils.UploadUtils;
/**
 * Servlet implementation class FoodAddServlet
 */
@WebServlet("/FoodAddServlet")
public class FoodAddServlet extends HttpServlet {
 private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FoodAddServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
 /**
  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  FoodDaoImpl FoodDaoImpl1=(FoodDaoImpl) this.getServletContext().getAttribute("FoodDaoImpl");
  List<Food> foodList=(List<Food>) this.getServletContext().getAttribute("foodList");
  if(foodList.isEmpty()) {
   System.out.println("从servletContext中获得的集合是空的");
  }
   try {
             //定义一个Map集合用于保存接收到的数据(即addFood.jsp提交的)
             Map<String, String> map = new HashMap<String, String>();
           //1、创建一个磁盘文件项工厂对象
             DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
             //2、创建一个核心的解析类
             ServletFileUpload servletFileUpload = new ServletFileUpload(diskFileItemFactory);
             //3、解析request请求,返回的是List集合,List集合中存放的是FileItem对象    
            List<FileItem> list = servletFileUpload.parseRequest(request);
            //4、遍历list,查看传递过来的数据是什么
             String url = null;
             for(FileItem fileItem:list) {
                 if(fileItem.isFormField()) {
                    //普通表单项:单选框、多选框、按钮
                     //接收表单项参数的值
                     String name = fileItem.getFieldName();//获得表单项的name属性的值
                     String value = fileItem.getString("UTF-8");
                     //存放在map中
                     map.put(name, value);
                 }else {
                    //文件上传项
                        //获得文件上传的名称
                        String fileName=fileItem.getName();
                        if(fileName!=null && !"".equals(fileName)) {
                        //通过工具类获得唯一文件名
                        String uuidFileName=UploadUtils.getUUIDFileName(fileName);
                        //获得文件上传的数据
                        InputStream is=fileItem.getInputStream();
                        //获得文件上传的路径
                        String path=this.getServletContext().getRealPath("/foodImage");
                        //将输入流对接到输出流
                        url=path+"\\"+uuidFileName;
                        OutputStream os=new FileOutputStream(url);
                        int len=0;
                        byte[] b=new byte[1024];
                        while((len=is.read(b))!=-1) {
                            os.write(b, 0, len);
                        }
                        is.close();
                        os.close();
                        }
                 }
             }
             
             if(foodList==null) 
                 System.out.println("从ContextServlet中获得的菜单是空的");
             
             if(foodList!=null) {
                 //检验网页上添加的菜名是否已存在
                 for(Food food:foodList) {
                     if(food.getId().equals(map.get("id"))) {
                         request.setAttribute("msg", "菜名已存在");
                         //菜名已存在,跳转到添加界面
                         request.getRequestDispatcher("/addFood.jsp").forward(request, response);
                         return;
            } 
                 }
             }
         
             //新添加的菜名可上传,封装相关数据
             Food food = new Food();
             food.setId(map.get("id"));
             food.setFoodName(map.get("foodName"));
             food.setTaste(map.get("taste"));
             food.setPath(url);
             food.setPrice((map.get("price")));
             food.setDescribe(map.get("description"));
             if( FoodDaoImpl1==null) {
                FoodDaoImpl1=new FoodDaoImpl();  
             }
             //添加到全局对象FoodDaoImpl1中
             FoodDaoImpl1.addFood(food);
             this.getServletContext().setAttribute("FoodDaoImpl1", FoodDaoImpl1);
             //跳转到展示食物界面
             request.getRequestDispatcher("/showFoodList.jsp").forward(request, response);
             //response.sendRedirect(request.getContextPath()+"/showFoodList.jsp");
         }
             
                 catch (FileUploadException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
 }
}
package com.imooc.servlet;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.imooc.food.Food;
import com.imooc.food.FoodDaoImpl;
/**
 * Servlet implementation class FoodDeleteServlet
 */
@WebServlet("/FoodDeleteServlet")
public class FoodDeleteServlet extends HttpServlet {
 private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FoodDeleteServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
 /**
  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  FoodDaoImpl FoodDaoImpl1=(FoodDaoImpl)this.getServletContext().getAttribute("FoodDaoImpl1");
        List<Food> foodList=FoodDaoImpl1.getDb();
        String deleteFoodId = request.getParameter("id");
        String msg=FoodDaoImpl1.getMsgString();
        boolean flag=false;
        for(Food food:foodList) {
            if(food.getId().equals(deleteFoodId))
                flag=true;
        }
        if(flag==false) {
            msg="输入的id无效,请重新输入";
            request.setAttribute("msg",msg);
        }
        if(flag==true) {
        FoodDaoImpl1.deleteFoodById(deleteFoodId);
        this.getServletContext().setAttribute("FoodDaoImpl1", FoodDaoImpl1);
        msg="根据id删除菜品已完成";
        request.setAttribute("msg",msg);
        request.getRequestDispatcher("/showFoodList.jsp").forward(request, response);
        }
 }
}
package com.imooc.servlet;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import com.imooc.food.Food;
import com.imooc.food.FoodDaoImpl;
import com.imooc.utils.UploadUtils;
/**
 * Servlet implementation class FoodUpdateServlet
 */
@WebServlet("/FoodUpdateServlet")
public class FoodUpdateServlet extends HttpServlet {
 private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FoodUpdateServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
 /**
  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  request.setCharacterEncoding("UTF-8");
        FoodDaoImpl FoodDaoImpl1=(FoodDaoImpl) this.getServletContext().getAttribute("FoodDaoImpl1");
        List<Food> foodList=FoodDaoImpl1.getDb();
        if(foodList.isEmpty()) {
            System.out.println("从ServletContext中获取的list是空的");
        }
        Map<String, String> map = new HashMap<String, String>();
        
        try {
            //1.创建磁盘工厂项文件
            DiskFileItemFactory diskFileItemFactory=new DiskFileItemFactory();
            //2.创建一个核心解析类
            ServletFileUpload servletFileUpload=new ServletFileUpload(diskFileItemFactory);
            //3.解析requst请求,返回的是List集合,List集合中存放的是FileItem对象
            List<FileItem> list = servletFileUpload.parseRequest(request);
            //4.遍历List集合,判断FileItem类型
             String url = null;
             for(FileItem fileItem:list) {
                 if(fileItem.isFormField()) {
                     String name=fileItem.getName();
                     String value=fileItem.getString("UTF-8");
                     map.put(name,value);
                 }else {
                     String fileName = fileItem.getName();
                     if(fileName!=null&&!"".equals(fileName)) {
                         //通过工具类获取获取唯一文件名
                         String uuidFileName=UploadUtils.getUUIDFileName(fileName);
                         //获得文件上传的数据
                         InputStream is=fileItem.getInputStream();
                         //获得文件上传的路径
                         String path = this.getServletContext().getRealPath("/foodImage");
                         url=path+"\\"+uuidFileName;
                         OutputStream os=new FileOutputStream(url);
                         int len=0;
                         byte[] b=new byte[1024];
                         while((len=is.read(b))!=-1) {
                             os.write(b, 0, len);
                         }
                         is.close();
                         os.close();
                     }
                 }
             }
//              检验菜名
                Iterator<Food> iterator = foodList.iterator();
                boolean flag = false;
                Food testFood = null;
                while(iterator.hasNext()) {
                    testFood = iterator.next();
                    if(testFood.getId().equals(map.get("id"))) {
                        flag=true;
                        break;
                    }
                }
                if(flag==false) {
                    String msg = "您要修改的id:"+ map.get("id") + "菜单里没有";
                    request.setAttribute("msg", msg);
                    request.getRequestDispatcher("/updateFood.jsp").forward(request, response);
                }else {
                    Food food = new Food();
                    food.setId(map.get("id"));
                    food.setFoodName(map.get("foodName"));
                    food.setTaste(map.get("taste"));
                    food.setPath(url);
                    food.setPrice((map.get("price")));
                    food.setDescribe(map.get("description"));
                    FoodDaoImpl1.updateFood(food);
                    System.out.println("更新后的food为"+food);
                    this.getServletContext().setAttribute(" FoodDaoImpl1",  FoodDaoImpl1);
                    request.getRequestDispatcher("/showFoodList.jsp").forward(request, response);
                   // response.sendRedirect(request.getContextPath()+"/showFoodList.jsp");
                }
        } catch (FileUploadException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
 }
}
package com.imooc.servlet;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import com.imooc.food.Food;
import com.imooc.food.FoodDaoImpl;
/**
 * Servlet implementation class InitServlet
 */
public class InitServlet extends HttpServlet {
 
 @Override
 public void init() throws ServletException {
  //创建FoodDaoImpl对象
  FoodDaoImpl FoodDaoImpl1=new FoodDaoImpl();
  // 创建一个List集合用于保存用户注册的信息
  List<Food> foodList=FoodDaoImpl1.getDb();
  //将List保存到ServletContext作用域中
  this.getServletContext().setAttribute("list", foodList);
  this.getServletContext().setAttribute("foodList", foodList);
 }
 
 
}
package com.imooc.servlet;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.imooc.food.Food;
import com.imooc.food.FoodDaoImpl;
/**
 * Servlet implementation class SelectServlet
 */
@WebServlet("/SelectServlet")
public class SelectServlet extends HttpServlet {
 private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SelectServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
 /**
  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  request.setCharacterEncoding("UTF-8");
        FoodDaoImpl FoodDaoImpl1=(FoodDaoImpl) this.getServletContext().getAttribute("FoodDaoImpl1");
        List<Food> list=FoodDaoImpl1.getDb();
        String foodName = request.getParameter("foodName");
        Food foodSearch=FoodDaoImpl1.getFoodByName(foodName);
        boolean flag=false;
        if(foodSearch!=null) {
            flag=true;
        }
        if(flag==false) {
               String msg = "对不起,您要查找的"+foodName+"我们家餐馆没有";
               request.setAttribute("msg", msg);
               request.getRequestDispatcher("/selectFoodByName.jsp").forward(request, response);
        }else {
            request.getSession().setAttribute("foodSearch", foodSearch);
            request.getRequestDispatcher("/showFoodByName.jsp").forward(request, response);
        }
 }
}
package com.imooc.utils;
import java.util.UUID;
public class UploadUtils {
 /**
  * 生成唯一的文件名 
  */
  public static String getUUIDFileName(String fileName) {
   //将文件名的前面部分进行截取:xx.jpg  -->  .jpg
   int idx=fileName.lastIndexOf(".");
   String extention=fileName.substring(idx);
   String uuidFileName=UUID.randomUUID().toString().replace("-", "")+extention;
   return uuidFileName;
  }
}
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath(); //path是project的名字
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>添加菜品</title>
<style type="text/css">
</style>
</head>
<body>
 <center>
  <h1>菜品添加</h1>
  <%
        String msg="";
        if(request.getAttribute("msg")!=null){
            msg=(String)request.getAttribute("msg");
        }
         %>
         <h2 style="color: red;font-weight: bolder;">${requestScope.msg }</h2>
  <form action="<%=basePath%>/FoodAddServlet" method="post" enctype="multipart/form-data">
   <table border="1px" width="400px" cellspacing="0px" cellpadding="0px">
    <tr>
     <td>菜品&nbsp;ID</td>
     <td><input type="text" name="id"></td>
    </tr>
    <tr>
     <td>菜&nbsp;&nbsp;名</td>
     <td><input type="text" name="foodName"></td>
    </tr>
    <tr>
     <td>口&nbsp;&nbsp;味</td>
     <td>
      <input type="radio" name="taste" value="香辣">香辣
      <input type="radio" name="taste" value="微辣">微辣
      <input type="radio" name="taste" value="麻辣">麻辣
      <input type="radio" name="taste" value="不辣">不辣
     </td>
    </tr>
    <tr>
     <td>菜品图片</td>
     <td><input type="file" name="foodImage"></td>
    </tr>
    <tr>
     <td>价&nbsp;&nbsp;格</td>
     <td><input type="text" name="price"></td>
    </tr>
    <tr>
     <td>菜品描述</td>
     <td>
      <textarea name="description"></textarea>
     </td>
    </tr>
    <tr   style="text-align:center;width:20px">
     <td colspan="2">
      <input type="submit" value="添加">
      <input type="reset" value="重置">
     </td>
    </tr>
   </table>
  </form>
 </center>
</body>
</html>


<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath(); //path是project的名字
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>菜品删除(根据ID删)</title>
<style type="text/css">
</style>
</head>
<body>
 <center>
  <h1>菜品删除(根据ID删除)</h1>
  <h2 style="color: red;font-weight: bolder;">${requestScope.msg }</h2>
  <form action="<%=basePath%>/FoodDeleteServlet" method="post">
   <table width="400px" border="1px" cellspacing="0px" cellpadding="0px">
    <tr>
     <td>菜品ID</td>
     <td><input type="text" name="id"></td>
    </tr>
    <tr>
     <td colspan="2" style="text-align:center"><input type="submit" value="删除"></td>
    </tr>
   </table>
  </form>
 </center>
</body>
</html>


<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
 <meta charset="UTF-8">
 <title>Document</title>
</head>
<body>
 <p><a href="addFood.jsp" target="main">菜品添加</a></p>
 <p><a href="selectFood.jsp" target="main">菜品查询</a></p>
 <p><a href="updateFood.jsp" target="main">菜品修改</a></p>
 <p><a href="deleteById.jsp" target="main">菜品删除</a></p>
</body>
</html>


<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath(); //path是project的名字
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>菜品查询选项页面</title>
<style type="text/css">
</style>
</head>
<body>
 <center>
  <p><a href="">查询所有菜品信息</a></p>
  <p><a href="">菜名查询</a></p>
 </center>
</body>
</html>



<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath(); //path是project的名字
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>菜名查询</title>
<style type="text/css">
</style>
</head>
<body>
 <center>
  <h1>菜名查询</h1>
  <%
            String msg = "";
            if(request.getAttribute("msg")!=null){
                msg = (String) request.getAttribute("msg");
            }
        %>
        <h2 style="color: red;font-weight: bolder;"><%=msg %></h2>
  <form action="<%=basePath%>/SelectServlet" method="post">
   <input type="hidden" name="type" value="2">
   <table width="400px" border="1px" cellspacing="0px" cellpadding="0px">
    <tr>
     <td>菜名</td>
     <td><input type="text" name="foodName"></td>
    </tr>
    <tr>
     <td colspan="2" style="text-align:center"><input type="submit" value="查询"></td>
    </tr>
   </table>
  </form>
 </center>
</body>
</html>


<%@page import="com.imooc.food.Food"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<%
    String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";
%>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>菜品管理系统</title>
</head>
<frameset rows="20%,*">
 <frame src="./top.jsp"></frame>
 <frameset cols="10%,*">
  <frame src="./left.jsp"></frame>
  <frame name="main"></frame>
 </frameset>
</frameset>
</html>


<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="com.imooc.food.Food"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<%
    String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";
%>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>菜品信息展示</title>
<style type="text/css">
</style>
</head>
<body>
 <center>
  <h1>菜品查询</h1>
  <table border="1px" cellspacing="0px" cellpadding="0px" width="800px">
   <thead>
    <tr>
     <th>菜品ID</th>
     <th>菜名</th>
     <th>口味</th>
     <th>菜品图片</th>
     <th>价格</th>
     <th>菜品描述</th>
    </tr>
   </thead>
   <tbody>
     <c:forEach items="${applicationScope.FoodDaoImpl1.getDb() }" var="food" >
    <tr>
     <td>${food.Id }</td>
     <td>${food.foodName }</td>
     <td>${food.taste }</td>
     <td><img src="${food.path}"></td>
     <td>${food.price }</td>
     <td>${food.describe }</td>
    </tr>
    </c:forEach>
   </tbody>
  </table>
 </center>
</body>
</html>



<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
 <meta charset="UTF-8">
 <title>菜品后台管理系统</title>
</head>
<body>
 <center>
  <h1>菜品后台管理系统</h1>
 </center>
</body>
</html>


<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath(); //path是project的名字
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>菜品修改(根据菜品ID进行修改)</title>
<style type="text/css">
</style>
</head>
<body>
 <center>
  <h1>根据菜品ID修改</h1>
  <form action="<%=basePath%>/FoodUpdateServlet" method="post" enctype="multipart/form-data">
   <table border="1px" width="400px" cellspacing="0px" cellpadding="0px">
    <tr>
     <td>修改ID</td>
     <td><input type="text" name="id"></td>
    </tr>
    <tr>
     <td>菜&nbsp;&nbsp;名</td>
     <td><input type="text" name="foodName"></td>
    </tr>
    <tr>
     <td>口&nbsp;&nbsp;味</td>
     <td>
      <input type="radio" name="taste" value="香辣">香辣
      <input type="radio" name="taste" value="微辣">微辣
      <input type="radio" name="taste" value="麻辣">麻辣
      <input type="radio" name="taste" value="不辣">不辣
     </td>
    </tr>
    <tr>
     <td>菜品图片</td>
     <td><input type="file" name="foodImage"></td>
    </tr>
    <tr>
     <td>价&nbsp;&nbsp;格</td>
     <td><input type="text" name="price"></td>
    </tr>
    <tr>
     <td>菜品描述</td>
     <td>
      <textarea name="description"></textarea>
     </td>
    </tr>
    <tr   style="text-align:center;width:20px">
     <td colspan="2">
      <input type="submit" value="修改">
      <input type="reset" value="重置">
     </td>
    </tr>
   </table>
  </form>
 </center>
</body>
</html>


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

7回答
好帮手慕柯南 2019-06-19 16:46:46

同学你好!同学这里的地址有误呢

http://img1.sycdn.imooc.com//climg/5d09f6710001ee8803580164.jpg

建议同学将<base href="">去掉,改为如下所示代码测试一下呢

http://img1.sycdn.imooc.com//climg/5d09f5ef0001450707810194.jpg

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~

提问者 weixin_慕哥8001276 2019-06-19 15:55:18

http://img1.sycdn.imooc.com//climg/5d09ea4e0001e8d603380790.jpg


是这个目录么?

提问者 weixin_慕哥8001276 2019-06-18 16:37:58

http://img1.sycdn.imooc.com//climg/5d08a2560001047809100214.jpg

http://img1.sycdn.imooc.com//climg/5d08a2560001b55009290215.jpg

菜品查询出现了上面的情况,是怎么回事?

  • 同学你好!同学贴一下自己出错时访问的地址,以及页面的目录结构。祝学习愉快~
    2019-06-18 18:19:00
  • 没懂老师是什么意思,还有就是代码都在上面的
    2019-06-18 20:30:17
  • 同学老师这里的目录结构可能和同学的不同,所以同学需要贴一下自己的目录结构,老师才能够帮同学准确的找到问题呢。
    2019-06-19 11:11:53
好帮手慕柯南 2019-06-18 11:24:13

同学你好!在循环显示图片时可以参考以下代码来完成。注意:将相应的属性名称更改为自己的属性名称

http://img1.sycdn.imooc.com//climg/5d08593800015c1307920632.jpg

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~

提问者 weixin_慕哥8001276 2019-06-17 20:47:46

没报错,显示了这个还有就是查询不能显示,报404错误http://img1.sycdn.imooc.com//climg/5d078bb0000197e010560156.jpg

好帮手慕阿莹 2019-06-17 10:02:26

http://img1.sycdn.imooc.com//climg/5d06f42b0001de8504590216.jpg

同学的图片地址要处理一下呦,可以复习 一下4-2课程中,老师讲解了图片的显示路径问题哦。建议同学复习一下,按照课程中的方法再处理一下。


如果我的回答解决了你的疑惑,请采纳!祝学习愉快!

  • 提问者 weixin_慕哥8001276 #1
    好难受啊,老师能不能给全部正确的代码参考参考,不会改啊。。。
    2019-06-17 11:18:07
  • 同学你好,我们是不提供参考答案的,同学有什么问题都可以在问答区提问,同学不能显示图片是报错吗?可以将报错信息贴一下。祝:学习愉快~
    2019-06-17 15:17:29
好帮手慕阿莹 2019-06-16 14:08:26

同学你好,同学的报错是空指针异常:

http://img1.sycdn.imooc.com//climg/5d05da0f0001169508880317.jpg

是指同学的FoodAddServlet 中的第47行报错了。

空指针异常,既有值为null的对象调用方法或属性导致的

那我们可以看一下这行代码:老师复制你的代码发现47行是一行注释,这个可能是因为复制进来后行数有变化,或者同学报错后有修改代码,

http://img1.sycdn.imooc.com//climg/5d05db1d0001e07e11260531.jpg

老师猜测是因为图中的41行引起的,同学可以运行一下,看看报错是否指向的是这行代码。(以后也要如图告诉老师具体是那一行呦,以便于老师知道同学的报错代码,只有行数,复制后有可能不同。)

看到同学再InitServlet中初始化了这个foodList。不知道同学的web.xml 中是否配置了该Servlet随着项目的启动而加载呢?

http://img1.sycdn.imooc.com//climg/5d05dc4f00016fbf09920878.jpg

另外,看到同学同时写了InitServlet和FoodDaoImpl,这两个择其一就可以。

要么存在集合db中,要么存在InitServlet初始化的list集合中。

选择其中一个就可以了。

如果我的回答解决了你的疑惑,请采纳!祝学习愉快!



  • 提问者 weixin_慕哥8001276 #1
    改了之后可以添加但是不能显示图片,是怎么回事
    2019-06-17 09:58:09
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
从网页搭建入门Java Web2018版
  • 参与学习           人
  • 提交作业       1088    份
  • 解答问题       10205    个

如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!

了解课程
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师