关于显示所有菜品出现500的问题!

关于显示所有菜品出现500的问题!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>菜品查询选项页面</title>
<style type="text/css">
 
</style>
</head>
<body>
    <center>
        <p><a href="/manu/ShowFoodServlet">查询所有菜品信息</a></p>
        <p><a href="selectFoodByName.html">菜名查询</a></p>
    </center>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package 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 domain.Food;
import utils.FoodDaoImpl;
 
/**
 * 显示所有菜品servlet
 */
@WebServlet("/ShowFoodServlet")
public class ShowFoodServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
 
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //实例化取全部数据方法
        FoodDaoImpl foodDaoImpl=new FoodDaoImpl();
         
        //调用方法取出所有食物,存储到Food类的List列表里
        List<Food>list=foodDaoImpl.getAllFood();
         
        //存储到request的属性中
        request.setAttribute("list", list);
        request.getRequestDispatcher("/showFoodList.jsp").forward(request, response);
    }
 
     
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
 
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<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>
<%  
    //直接读取从servlet传过来的request数据
    List<Food> foodList = (List<Food>)request.getAttribute("list");
    //判断如果这个list不为空,则循环输出所有数据,如果为空则提示.
        for(Food food:foodList){
             String id =food.getId ;
             String name = food.getName;
             String taste = food.getTaste;
             String path = food.getPath;
             String price = food.getPrice;
             String info = food.getInfo;
%>
                <tr>
                    <td><%=id %></td>
                    <td><%= %></td>
                    <td><%= %></td>
                    <td><img src="<%= %>"></td>
                    <td><%= %></td>
                    <td><%= %></td>
                </tr>
<% 
    }
%>
            </tbody>
        </table>
    </center>
</body>
</html>

点查询所有菜单后出现500错误!菜品可以正常添加,显示所有菜品的方法是return db;

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

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

4回答
提问者 龍彦宏 2019-01-22 17:33:18

老师我重申一下自己的问题,应该是eclipse的设置问题,我重配置了软件,倒入包后包上面出现红叉,这块就不会调整了,还有就是运行菜品查询时候,输入查询名称,servlet做网页jsp跳转的时候出现500错误,我觉得应该是软件的问题,如果有相应的调试方法请告知。

  • 你好同学~很抱歉答复你慢了,老师答问答的顺序是按照时间的顺序进行答疑的,建议同学不要总在自己的问题下回答,否则系统会自动跟新问题的时间,导致问题靠后。另外同学出现红叉部分的报错提示是什么呢?还有出现500的报错提示什么?建议你将报错提示粘贴一下,方便老师先判断你是那个地方出现了问题呢,祝学习愉快~
    2019-01-22 17:59:54
提问者 龍彦宏 2019-01-22 16:20:38

老师,500错误应该是eclipse的问题,我好像设置了什么导致的,更新了JDK包才导致的.有什么好的修复方法吗.

提问者 龍彦宏 2019-01-22 15:02:35

还有老师我要反映一下,今天回复太慢了!

我这个报500错误到底是因为什么都胡没搞明白,代码都是参照之前教学写的没有任何问题.特别奇怪,要不我直接交作业好了.写不下去了.

提问者 龍彦宏 2019-01-22 11:11:20

再補充一下,现在做完搜索菜品也是500出错,不知道哪里出了问题.补上代码.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package utils;
 
import java.util.ArrayList;
import java.util.List;
 
import domain.Food;
 
 
/**
 * 菜品处理类
 */
public class FoodDaoImpl {
    //存放菜品List集合
    private static final List<Food> db = new ArrayList<Food>();
     
    //添加菜品
    public void addFood(Food food){
        db.add(food);
    }
     
    //显示所有菜品
    public List<Food>getAllFood(){
        return db;
    }
     
    //根据菜品名称查询菜品信息
    public List<Food >getFoodByName(String foodName){
        List<Food > foodList = new ArrayList<>();//创建一个list集合接收数据
            Food getFood = null;
            for(Food food : db){
                if(food.getName().equals(foodName)){
                    getFood = food;
                    foodList.add(getFood);
                }
            }
            return foodList ;
        }
     
     
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<!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>
        <form action="/manu/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="name"></td>
                </tr>
                <tr>
                    <td colspan="2" style="text-align:center"><input type="submit" value="查询"></td>
                </tr>
            </table>
        </form>
    </center>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package servlet;
 
import java.io.IOException;
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 domain.Food;
import utils.FoodDaoImpl;
 
/**
 * 通过名称查询菜品名称
 */
@WebServlet("/SelectServlet")
public class SelectServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
 
 
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //从表单获取查询名称
        String foodName = request.getParameter("name");
        //实例化调取命令查询对应食物集合
        FoodDaoImpl foodDaoImpl = new FoodDaoImpl();
        Food food = (Food) foodDaoImpl.getFoodByName(foodName);
  
        request.setAttribute("food",food);
        request.getRequestDispatcher("/showFoodList2.jsp").forward(request, response);
    }
 
 
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
 
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<%@ page import="java.util.List" %>
<%@ page import="domain.Food" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<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>
         <%
            List<Food> foodList = (List<Food>) request.getAttribute("list");
            Food food = (Food)request.getAttribute("food");
            if(food!=null){%>
         <tr>
            <td><%=food.getId()%></td>
            <td><%=food.getName()%></td>
            <td><%=food.getTaste()%></td>
            <td><img src="<%=food.getPath()%>"></td>
            <td><%=food.getPrice()%></td>
            <td><%=food.getDescription()%></td>
         </tr>
         <% }else{
            for (Food food1 : foodList) {%>
         <tr>
            <td><%=food1.getId()%></td>
            <td><%=food1.getName()%></td>
            <td><%=food1.getTaste()%></td>
            <td><img src="<%=food1.getPath()%>"></td>
            <td><%=food1.getPrice()%></td>
            <td><%=food1.getDescription()%></td>
         </tr>
         <%}
         }%>
         </tbody>
      </table>
   </center>
</body>
</html>

老师...我觉得自己做这个太困难了,没有教程对这种增删改查的,可否把后面的修改和删除的方法都铁给我...这块太耽误时间了,我得赶紧学后面的了.

问题已解决,确定采纳
还有疑问,暂不采纳

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

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

0 星
Java Web基础入门2018版
  • 参与学习       716    人
  • 提交作业       185    份
  • 解答问题       1363    个

会Java?懂前端基础?想学后台开发?那么,赶快来学习《Java Web入门》路径吧。本路径主要介绍Java Web的基础知识,并配有大量案例,定会让你收获多多!

了解课程
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

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