jsp跳转空白?

新手上路,请多包涵

controller调用方法时跳转jsp是空白的?

Dao层方法

public int UpdateMenu(Menu menu) throws SQLException {
    int result = 0; 
    try {
        
        conn = db.getConnection();
        String sql = "UPDATE menu SET menucategory = ?, menumethod = ?, menumain = ?, menuaccessory = ?, menuflavour = ?, menustep = ? WHERE menuname = ?";
        
        ps = conn.prepareStatement(sql);
        ps.setString(1, menu.getMenucategory());  
        ps.setString(2, menu.getMenumethod());  
        ps.setString(3, menu.getMenumain());  
        ps.setString(4, menu.getMenuaccessory());  
        ps.setString(5, menu.getMenuflavour());  
        ps.setString(6, menu.getMenustep());
        ps.setString(7, menu.getMenuname());
        
        result = ps.executeUpdate();
        return result > 0 ? 0 : 1;
    } catch (SQLException e) {  
        e.printStackTrace();
        return 1;
    }finally {
        conn.close();
        ps.close();
    }   
}

controller调用

else if("update".equals(cmd)) {
            
            String menuname = new String(request.getParameter("menuname").getBytes(StandardCharsets.ISO_8859_1),StandardCharsets.UTF_8);
            String menucategory = new String(request.getParameter("menucategory").getBytes(StandardCharsets.ISO_8859_1),StandardCharsets.UTF_8);
            String menumethod = new String(request.getParameter("menumethod").getBytes(StandardCharsets.ISO_8859_1),StandardCharsets.UTF_8);
            String menumain = new String(request.getParameter("menumain").getBytes(StandardCharsets.ISO_8859_1),StandardCharsets.UTF_8);
            String menuaccessory = new String(request.getParameter("menuaccessory").getBytes(StandardCharsets.ISO_8859_1),StandardCharsets.UTF_8);
            String menuflavor = new String(request.getParameter("menuflavor").getBytes(StandardCharsets.ISO_8859_1),StandardCharsets.UTF_8);
            String menustep = new String(request.getParameter("menustep").getBytes(StandardCharsets.ISO_8859_1),StandardCharsets.UTF_8);
            
            Menu menu = new Menu(menuname,menucategory,menumethod,menumain,menuaccessory,menuflavor,menustep);
            
            
            try {
                int i;
                i = menuService.UpdateMenu(menu);
                if(i == 0) {
                    response.sendRedirect("MenuC?cmd=showMenu");
                
                }else{
                    request.setAttribute("operation","更新");
                    request.getRequestDispatcher("failure.jsp").forward(request, response);
                }
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

jsp页面

<%@ 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 PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
        * {
            margin: 0;
            padding: 0;
            outline: none;
            box-sizing: border-box;
        }

        body {
            display: flex;
            align-items: center;
            justify-content: center;
            min-height: 100vh;
            background: linear-gradient(-135deg, #c850c0, #4158d0);
        }

        .wrapper {
            magin-top: 50px;
            width: 500px;
            background-color: #fff;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
            margin-top: 100px;
        }

        .LoginTitle {
            font-size: 33px;
            text-align: center;
            letter-spacing: 4px;
        }

        .contentBox {
            margin-top: 30px;
        }

        .wrapper .input-data {
            width: 100%;
            height: 40px;
            margin-bottom: 20px;
            position: relative;
        }

        .wrapper .input-data input {
            width: 100%;
            height: 100%;
            border: none;
            border-bottom: 2px solid silver;
            font-size: 16px;
        }

        .input-data input:focus ~ label, .input-data input:valid ~ label {
            transform: translateY(-25px);
            font-size: 15px;
            color: #4158D0;
        }

        .wrapper .input-data label {
            position: absolute;
            bottom: 10px;
            left: 0;
            color: grey;
            pointer-events: none;
            transition: all 0.3s ease;
        }

        .wrapper .input-data .underline {
            position: absolute;
            bottom: 0px;
            height: 2px;
            width: 100%;
        }

        .input-data .underline:before {
            position: absolute;
            content: "";
            height: 100%;
            width: 100%;
            background: #4158D0;
            transform: scaleX(0);
            transition: transform 0.3s ease;
            maegin-top: 100px;
        }

        .input-data input:focus ~ .underline:before, .input-data input:valid ~
        .underline:before {
            transform: scaleX(1);
        }

        .kuang1 {
            color: gray;
            margin-bottom: 14px;
            display: flex;
        }

        .name {
            color: gray;
        }

        .xuanze {
            width: 160px;
            display: flex;
            justify-content: space-between;
        }

        .ziti {
            color: #4158d0;
        }

        .bottom {
            width: 200px;
            height: 50px;
            margin: auto;
            margin-top: 30px;
        }

        .anniu {
            width: 200px;
            height: 50px;
            border-radius: 20px;
            border: none;
            font-size: 18px;
            letter-spacing: 7px;
            color: white;
            background: linear-gradient(-135deg, #c850c0, #4158d0);
        }
    </style>
</head>
<body>
<div id="box">
    <%request.getAttribute("NeedUpdateMenu");%>
    <form action="${pageContext.request.contextPath}/MenuC?cmd=update" method="post">
        <div class="wrapper">
            <div class="LoginTitle">修改菜单信息</div>
            <div class="contentBox">
                <div class="input-data">
                    <input class="ziti" type="text" value="${NeedUpdateMenu.menuname}" name="menuname"> 
                    <div class="underline"></div>
                    <label>菜品名称</label>
                </div>
                <div class="input-data">
                    <input class="ziti" type="text" value="${NeedUpdateMenu.menucategory}" name="menucategory">
                    <div class="underline"></div>
                    <label>菜谱类型</label>
                </div>
                <div class="input-data">
                    <input class="ziti" type="text" value="${NeedUpdateMenu.menumethod}" name="menumethod">
                    <div class="underline"></div>
                    <label>烹饪方式</label>
                </div>
                <div class="input-data">
                    <input class="ziti"  type="text" value="${NeedUpdateMenu.menumain}" name="menumain">
                    <div class="underline"></div>
                    <label>菜品主料</label>
                </div>
                <div class="input-data">
                    <input class="ziti"  type="text" value="${NeedUpdateMenu.menuaccessory}" name="menuaccessory">
                    <div class="underline"></div>
                    <label>菜品辅料</label>
                </div>
                <div class="input-data">
                    <input class="ziti" type="text" value="${NeedUpdateMenu.menuflavour}" name="menuflavor" >
                    <div class="underline"></div>
                    <label>菜品调料</label>
                </div>
                <div class="input-data">
                    <input class="ziti"  type="text" value="${NeedUpdateMenu.menustep}" name="menustep">
                    <div class="underline"></div>
                    <label>烹饪步骤</label>
                </div>

                <div class="kuang1">
                    <div class="bottom">
                        <input class="anniu" type="submit" value="修改">
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>


</body>
</html>
阅读 415
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题