Giúp mình tìm lỗi NullPointerException với hix !!!mình phải nộp bài gấp lắm ạ!!! cảm ơn mọi người

Chiptk6761

New Member
24/4/20
9
1
3
japan
Code:
<%@ page language="java" contentType="text/html; charset=Windows-31J"
    pageEncoding="Windows-31J"%>
<%@ page import="java.util.*"%>
<% List<String> al = (List<String>) session.getAttribute("al"); %>
<jsp:useBean id="bn" scope="session" class="admin.insertBean" />

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=Windows-31J">
    <title>入力フォームサンプル</title>
    <link type="text/css" rel="stylesheet" href="style.css" />
<link type="text/css" rel="stylesheet" href="normalize.css" />

  </head>
  <body>
  <div id="container">
    <h1>講座登録</h1>
    <span>* は入力必須です。</span>
    <% if (al.size() != 0) {%>
    <div>
        <% for (int i = 0; i < al.size(); i++) {%>
            &nbsp;&nbsp;<%=al.get(i)%><br/>
        <% }%>
    <% }%><br/>
    </div>
    <form action="Insertcourse" method="post">
      <table>
        <tr>
          <td>講座番号<span>*</span></td>
          <td><input type="text" name="course_no" /></td>
        </tr>
        <tr>
          <td>講座名<span>*</span></td>
          <td><input type="text" name="course_name"/></td>
        </tr>
        <tr>
          <td>講座開催日<span>*</span></td>
          <td>
            <select name="year">
            <% Calendar cl=Calendar.getInstance();
               int year = cl.get(Calendar.YEAR);
               for (int i = year-5; i <= year; i++) {
            %>

              <option value="<%=i %>"
              ><%=i %>
              </option>

            <% } %>
            </select> 年

            <select name="month">
            <% for (int i = 1; i <= 12; i++) { %>

              <option value="<%=i %>"
              ><%=i %>
              </option>

            <% } %>
            </select> 月

            <select name="day">
            <% for (int i = 1; i <= 31; i++) { %>

              <option value="<%=i %>"
              ><%=i %>
              </option>

            <% } %>
            </select> 日
          </td>
        </tr>
        <tr>
        <td>開発時刻<span>*</span></td>
        <td>
        <select name="starthour">
            <% for (int i = 10; i <= 18; i++) { %>

              <option value="<%=i %>"
              ><%=i %>
              </option>

            <% } %>
            </select> 時

            <select name="startminute">
            <% for (int i = 0; i <= 59; i++) { %>

              <option value="<%=i %>"
              ><%=i %>
              </option>

            <% } %>
            </select> 分</td>
        </tr>
        <tr>
        <td>終了時刻<span>*</span></td>
        <td>
        <select name="endhour">
            <% for (int i = 10; i <= 18; i++) { %>

              <option value="<%=i %>"
              ><%=i %>
              </option>

            <% } %>
            </select> 時

            <select name="endminute">
            <% for (int i = 0; i <= 59; i++) { %>

              <option value="<%=i %>"
              ><%=i %>
              </option>

            <% } %>
            </select> 分</td>
        </tr>
        <tr>
          <td>定員<span>*</span></td>
          <td>
           <input type="text" name="numberps"/></td>

        </tr>

      </table>
      <br />
     <input class="button" type="submit" name="backmenu" value="戻る" />
      <input class="button" type="submit" name="next" value="確認" />

    </form>
    </div>
  </body>
</html>
 

Joe

Thành viên VIP
21/1/13
2,935
1,304
113
It is NOT Java codes, but a XML with embedded JAVA. And XML NEVER throws NullPointerException.
 

Joe

Thành viên VIP
21/1/13
2,935
1,304
113
yes, Its JSP =HTML with embedded JAVA
and HTML won't throw NullPointerException. Where is the JAVA codes where the line (number) of NullPointerException was thrown?

Further: I have helped you several times and got NO feedback, NO thanks or whatsoever. Japanese are very courteous and you should learn from them and be courteous.
 
Sửa lần cuối:

Chiptk6761

New Member
24/4/20
9
1
3
japan
and HTML won't throw NullPointerException. Where is the JAVA codes where the line (number) of NullPointerException was thrown?

Further: I have helped you several times and got NO feedback, NO thanks or whatsoever. Japanese are very courteous and you should learn from them and be courteous.
Code:
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


public class Insertcourse extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         response.setContentType("text/html; charset=Windows-31J");
            request.setCharacterEncoding("Windows-31J");
            final String NEXTPAGE_PATH = "insertConfCourse.jsp";
            final String REINPUT_PATH = "input.jsp";

            // セッションオブジェクト生成(取得)
            HttpSession session = request.getSession();
            String path="";

            // 入力データを取得
            String course_no = request.getParameter("course_no");
            String course_name = request.getParameter("course_name");
            String year = request.getParameter("year");
            String month = request.getParameter("month");
            String day = request.getParameter("day");
            String starthour = request.getParameter("starthour");
            String startminute = request.getParameter("startminute");
            String endhour = request.getParameter("endhour");
            String endminute = request.getParameter("endminute");
            String numberps=request.getParameter("numberps");
            insertBean bn = new insertBean();
            bn.setCourse_no(course_no);
            bn.setCourse_name(course_name);
            bn.setYear(year);
            bn.setMonth(month);
            bn.setDay(day);
            bn.setThe_date(year + "年" + month + "月" + day + "日");
            bn.setStarthour(starthour);
            bn.setStartminute(startminute);
            bn.setStart_time(starthour+"時"+startminute+"分");
            bn.setEndhour(endhour);
            bn.setEndminute(endminute);
            bn.setEnd_time(endhour+"時"+endminute+"分");
            bn.setNumberps(numberps);


            // InsertBeanオブジェクトをsessionにセット
            session.setAttribute("bn", bn);
            //ArrayList al = new ArrayList();
            List<String> al = new ArrayList<String>();
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            if ((course_no == null) || (course_no.equals(""))) {
                al.add("講座番号 必須項目です");
            }else if(course_no.length()>4){
                al.add("講座番号is break/exceed the leght limit");
            }
            if ((course_name == null) || (course_name.equals(""))) {
                al.add("講座名 必須項目です");
            }
            if ((year == null) || (year.equals(""))) {
                al.add("講座開催日 必須項目です");
            }
            if ((month == null) || (month.equals(""))) {
                al.add("講座開催日 必須項目です");
            }
            if ((day == null) || (day.equals(""))) {
                al.add("講座開催日 必須項目です");
            }
            if ((starthour == null) || (starthour.equals(""))) {
                al.add("開発時刻 必須項目です");
            }
            if ((startminute == null) || (startminute.equals(""))) {
                al.add("開発時刻 必須項目です");
            }
            if ((endhour == null) || (endhour.equals(""))) {
                al.add("終了時刻 必須項目です");
            }
            if ((endminute == null) || (endminute.equals(""))) {
                al.add("終了時刻 必須項目です");
            }
            if ((numberps == null) || (numberps.equals(""))) {
                al.add("定員 必須項目です");

            }else if(Integer.parseInt(numberps)<1 || Integer.parseInt(numberps)>50) {
                al.add("「定員」は1以上、50以下で入力してください");
            }


            if (al.size() != 0) {
                 path = REINPUT_PATH;
                 out.println(al);
                 session.setAttribute("al", al);
                 session.setAttribute("bn", bn);

            } else {

                path = NEXTPAGE_PATH;
                session.setAttribute("bn", bn);

            }
            RequestDispatcher rd = request.getRequestDispatcher(path);
            rd.forward(request, response);

        }


     public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
            doGet(req, res);

        }

}
 

Joe

Thành viên VIP
21/1/13
2,935
1,304
113
First: I asked you:
and HTML won't throw NullPointerException. Where is the JAVA codes where the line (number) of NullPointerException was thrown?
and I got a source without the error messages showing the exception lines.

Then:
Further: I have helped you several times and got NO feedback, NO thanks or whatsoever. Japanese are very courteous and you should learn from them and be courteous.
If you again won't give me any feedback then it's the last time I help you. OK?


So, where are the errors? They are one of the following coding mistakes:

Code:
<% List<String> al = (List<String>) session.getAttribute("al"); %>
....
<% if (al.size() != 0) {%>
in the Servlet:
Java:
            if (al.size() != 0) {
                 path = REINPUT_PATH;
                 out.println(al);
                 session.setAttribute("al", al);    // <<-------OK for the JSP
                 session.setAttribute("bn", bn);

            } else {
                // where is the line: session.setAttribute("al", al);   ?????? <<---NullPointerException in JSP is the result !!
                path = NEXTPAGE_PATH;
                session.setAttribute("bn", bn);

            }
 
Sửa lần cuối:
  • Like
Reactions: Chiptk6761

Chiptk6761

New Member
24/4/20
9
1
3
japan
First: I asked you:

and I got a source without the error messages showing the exception lines.

Then:

If you again won't give me any feedback then it's the last time I help you. OK?


So, where are the errors? They are one of the following coding mistakes:

Code:
<% List<String> al = (List<String>) session.getAttribute("al"); %>
....
<% if (al.size() != 0) {%>
in the Servlet:
Java:
            if (al.size() != 0) {
                 path = REINPUT_PATH;
                 out.println(al);
                 session.setAttribute("al", al);    // <<-------OK for the JSP
                 session.setAttribute("bn", bn);

            } else {
                // where is the line: session.setAttribute("al", al);   ?????? <<---NullPointerException in JSP is the result !!
                path = NEXTPAGE_PATH;
                session.setAttribute("bn", bn);

            }
Im so sorry about my impolite thing makes you have to grow angry, i think now i cant explain one`s attidute. you are right, i dont know that have like button in the website , even forgotten feedback , that so bad. i will remmember your comment and dont repeat in the future.
thank you and so sorry.
 
Last edited by a moderator:
  • Like
Reactions: Joe