Home>

An error will occur even if you try to register the value that was output to the confirmation screen in the DB.

Error details

java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString (NumberFormatException.java:65) ~ [na: 1.8.0_231]
    at java.lang.Integer.parseInt (Integer.java:592) ~ [na: 1.8.0_231]
    at java.lang.Integer.parseInt (Integer.java:615) ~ [na: 1.8.0_231]
    at com.example.web.db.MogipuroController.teacherNissiend (MogipuroController.java:165) ~ [classes /: na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) ~ [na: 1.8.0_231]
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) ~ [na: 1.8.0_231]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) ~ [na: 1.8.0_231]
    at java.lang.reflect.Method.invoke (Method.java:498) ~ [na: 1.8.0_231]
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke (InvocableHandlerMethod.java:190) ~ [spring-web-5.2.1.RELEASE.jar: 5.2.1.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest (InvocableHandlerMethod.java:138) ~ [spring-web-5.2.1.RELEASE.jar: 5.2.1.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle (ServletInvocableHandlerMethod.java:106) ~ [spring-webmvc-5.2.1.RELEASE.jar: 5.2.1.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod (RequestMappingHandlerAdapter.java:888) ~ [spring-webmvc-5.2.1.RELEASE.jar: 5.2.1.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal (RequestMappingHandlerAdapter.java:793) ~ [spring-webmvc-5.2.1.RELEASE.jar: 5.2.1.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle (AbstractHandlerMethodAdapter.java:87) ~ [spring-webmvc-5.2.1.RELEASE.jar: 5.2.1.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch (DispatcherServlet.java:1040) ~ [spring-webmvc-5.2.1.RELEASE.jar: 5.2.1.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService (DispatcherServlet.java:943) ~ [spring-webmvc-5.2.1.RELEASE.jar: 5.2.1.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest (FrameworkServlet.java:1006) ~ [spring-webmvc-5.2.1.RELEASE.jar: 5.2.1.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doGet (FrameworkServlet.java:898) ~ [spring-webmvc-5.2.1.RELEASE.jar: 5.2.1.RELEASE]
    at javax.servlet.http.HttpServlet.service (HttpServlet.java:634) ~ [tomcat-embed-core-9.0.27.jar: 9.0.27]
    at org.springframework.web.servlet.FrameworkServlet.service (FrameworkServlet.java:883) ~ [spring-webmvc-5.2.1.RELEASE.jar: 5.2.1.RELEASE]
    at javax.servlet.http.HttpServlet.service (HttpServlet.java:741) ~ [tomcat-embed-core-9.0.27.jar: 9.0.27]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:231) ~ [tomcat-embed-core-9.0.27.jar: 9.0.27]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:166) ~ [tomcat-embed-core-9.0.27.jar: 9.0.27]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter (WsFilter.java:53) ~ [tomcat-embed-websocket-9.0.27.jar: 9.0.27]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:193) ~ [tomcat-embed-core-9.0.27.jar: 9.0.27]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:166) ~ [tomcat-embed-core-9.0.27.jar: 9.0.27]
    at

This
<! DOCTYPE html>
<html xmlns: th = "http://www.thymeleaf.org">
<head>
<meta charset = "UTF-8" />
<title>Timely confirmation</title>
</head>
    <body>
     Registration confirmation 
        <p>* Check the input contents.</p>
        <form th: action = "@ {/ insert-ensyu1-end}" th: object = "${insertMogipuroForm}" method = "post">
        <table>
            <tr>
                <td>Children ID</td>
                <td>
                <span th: text = "${insertMogipuroForm.childrenid}"></span>
                </td>
        </tr>
        <tr>
        <td>Kindergarten Name</td>
            <td>
        <span th: text = "${insertMogipuroForm.name}"></span>
    </td>
    </tr>
    <tr>
            <td>Date filled</td>
                <td>
                <span th: text = "${insertMogipuroForm.year}"></span>year
    </td>
                <td>
                <span th: text = "${insertMogipuroForm.month}"></span>month
    </td>
    <td><span th: text = "${insertMogipuroForm.day}"></span>day
    </td>
            </tr>
<tr>
    <td>Communications</td>
        <td>
                <span th: text = "${insertMogipuroForm.communication}"></span>
                </td>
</tr>
    </table>
<input type = "submit" name = "timely_btn" value = "register" />
<input type = "submit" name = "back_btn" value = "back" />
</form>
</html>
package com.example.domain;
import java.util.List;
public class MogipuroInfo {
    private String timelyid;
    private String id;
    private String name;
    private String classs;
    private String sleepstarttime;
    private String sleependtime;
    private String mood;
    private String poop;
    private String meal;
    private String phase;
    // Search list
    private String searchid;
    public String serchtimelyid;
    private String searchstartyear;
    private String searchstartmonth;private String searchstartday;
    private String searchendyear;
    private String searchendmonth;
    private String searchendday;
    // Parent's
    private String pickuptime;
    private String communication;
    private String daybookwriter;
    private String writedate;
    private String childrenid;
    private String childrenname;
    private String timelywriter;
    private String year;
    private String month;
    private String day;
    private String startmin;
    private String endmin;
    private List<String>yearList;
    private List<String>monthList;
    private List<String>dayList;
    private List<String>startTimeList;
    private List<String>startMinList;
    private List<String>endTimeList;
    private List<String>endMinList;
    private String startwritedate;
    private String endwritedate;
    private String writedatetime;
    private String communicaton;
    private String starttime;
    private String endtime;
    private String theDate;
    private String startTime1;private String endTime1;
    public String getTheDate () {
        return theDate;
    }
}
    // Redirect from diary registration confirmation to completion screen  DB registration
    @RequestMapping (value = "/ teacher-nissi-end", params = "nissi_btn")
    public String teacherNissiend (@ModelAttribute ("insertMogipuroForm") InsertMogipuroForm form) {
        // Instantiate the domain class used for data registration
        MogipuroInfo inputNissiInfo = new MogipuroInfo ();
// Copy form class value to domain class
        BeanUtils.copyProperties (form, inputNissiInfo);
// convert for registration and registration
        int year = Integer.parseInt (form.getYear ());
        int month = Integer.parseInt (form.getMonth ());
        int day = Integer.parseInt (form.getDay ());
        String sleepstarttime1 = form.getSleepstarttime1 ();
        String sleependtime1 = form.getSleependtime1 ();
        String sleepstarttime2 = form.getSleepstarttime2 ();
        String sleependtime2 = form.getSleependtime2 ();
        String theDate = String.format ("% 04d% 02d% 02d", year, month, day);
        MogipuroInfo.setTheDate (theDate);
        MogipuroInfo.setStartTime1 (sleepstarttime1 + ":" + sleependtime1);
        MogipuroInfo.setEndTime1 (sleepstarttime2 + ":" + sleependtime2);
        System.out.print (form.getYear ());
// Call service process to register data
        service.inputNissiInfo (inputNissiInfo);
        return "redirect:/teacher-nissi-end? finish";
  • Answer # 1

    java.lang.NumberFormatException: For input string: ""
    ...
    ...
    com.example.web.db.MogipuroController.teacherNissiend (MogipuroController.java:165)
    As shown in

    , an exception is thrown when trying to convert an empty character string to int on line 165 of the Controller class. Probably

    int year = Integer.parseInt (form.getYear ());
    int month = Integer.parseInt (form.getMonth ());


    In either of the cases, the value is obtained from the form but the value is not entered.

    I imagine that you have seen the code of the HTML template, but if you register from the registration confirmation screen, you need a mechanism to take over what you entered on the previous screen.
    In other words, the registration information is not sent from the screen.

    The easiest way is to use a session that temporarily holds the input information and acquire the value from the session when registering data.