编写异常处理程序

时间:2019-04-19 05:33:07

标签: java spring-mvc jsp

在给定的问题中,showstatus.jsp无法验证'seat'变量的空值。如何在“ seat”变量中添加验证,该变量将在重定向到另一个页面之前检查用户是否选择了任何座位? 我尝试添加spring mvc的所有注释和所有验证,但未获得正确的输出。实际上,我尝试将席位值设置为null时重定向到相同的showseatstatus.jsp

controller.java

@RequestMapping("/showtimes/choose-slot/{show_id}/showseatstatus")
public String showSeatstatus(@PathVariable String show_id,HttpSession session,ModelMap m) {
    System.out.println(show_id);
    String str3=show_id;
    List<Show> shows = showdao.getShowByShowid(show_id);
    Iterator<Show> itr = shows.iterator();
    Show s=null;
    while (itr.hasNext()) {
         s = itr.next();
    }
    System.out.println(s.getSeat_status());
    session.setAttribute("str3", str3);
    m.addAttribute("s", s);
    return "showseatstatus";
}
@RequestMapping("/payment")
public String bookSeats(HttpServletRequest request,HttpSession session,ModelMap m) {
    String[] seats = request.getParameterValues("seat");
    int count=0;
    for(int i=0;i<seats.length;i++) {
        count=count+1;
    }
    session.setAttribute("count",count);
    String show_id = request.getParameter("show_id");

    Show show = showdao.getShowByShow_id(show_id);
    String event_id = show.getEvent_id();
    Event ev = evdao.getEventByEventId(event_id);

    Booking booking = new Booking();
    booking.setSeats(seats);
    booking.setShow(show);
    booking.setEvent(ev);
    m.addAttribute("booking", booking);
    return "payment-page";
}

showseatstatus.jsp

<%
            String url = request.getRequestURL().toString();
            String baseUrl = url.substring(0, url.length() - request.getRequestURI().length())
                    + request.getContextPath() + "/";
            Show s = (Show) request.getAttribute("s");
            String seatstatus = s.getSeat_status();
            out.print("<form action='" + baseUrl + "payment' method='get'>");
            int jmax;
            for (int i = 0, k = 0; i < 8; i++) {

                out.print("<span class='vertical rownumber'>S"+i+"</span>");

                if (i < 2 || i == 7){
                    jmax = 8; out.print("<span style='padding-left:32px'></span>");
                }
                else
                    jmax = 10;
                for (int j = 0; j < jmax; j++) {

                    if (j == jmax / 2)
                        out.print("<span style='padding-left:20px'></span>");
                    if (seatstatus.charAt(k++) == '1') {
                        out.print(
                                "<input type='checkbox' id='cb" + (k - 1) + "' name='seat' value='" + (k - 1) + "'> ");
                        out.print("<label for='cb" + (k - 1) + "'></label>");
                    } else {
                        out.print("<input type='checkbox' class='disabledcheckbox' id='cb" + (k - 1)
                                + "' name='seat' disabled='disabled'> ");
                        out.print("<label for='cb" + (k - 1) + "'></label>");
                        //out.print("<input type='checkbox' checked='checked' disabled='disabled' > ");
                    }
                }

                if (i < 2 || i == 7){
                    jmax = 8; out.print("<span style='padding-left:32px'></span>");
                }
                out.print("<br/>");

            }
            out.print("<hr>");
            out.print("<input type='hidden' name='show_id' value='" + 
            s.getShow_id() + "'>");
            out.print("<input type='submit' value='Book Seats'>");
        %>

0 个答案:

没有答案