- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在处理个人项目时,我收到 NumberFormatException。当表单尝试将日期变量显示为字符串时,会发生此错误。问题是该设置与项目的其他部分相同,并且运行良好。
我使用两个 Controller ,一个用于不同的页面子集,它们显示并允许操作不同但相关的信息。就像病人和他们的医生一样。
这是表格:
CREATE TABLE bmi(
bmi_id INT(14) NOT NULL AUTO_INCREMENT,
date_weight DATE,
height DECIMAL(5,2),
weight DECIMAL(5,2),
bmi DECIMAL(5,2),
patient_id INT(11),
PRIMARY KEY(bmi_id),
CONSTRAINT wei_pat_fk FOREIGN KEY(patient_id) REFERENCES patient(patient_id)
)ENGINE=InnoDB auto_increment=1 default charset=latin1;
这是 BMI 对象:
@Entity
@Table(name="table")
public class BMI {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="bmi_id")
private int bmiId;
@CreationTimestamp
@Temporal(TemporalType.DATE)
@Column(name="date_weight")
@DateTimeFormat(pattern = "dd/MM/yyyy")
private Date createdW;
@Column(name="weight")
private BigDecimal weight;
@Column(name="height")
private BigDecimal height;
@Column(name="bmi")
private BigDecimal bmi;
//Getter Setters
}
病人对象:
@Entity
@Table(name = "patient")
public class Patient {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "patient_id")
private int patientId;
@NotBlank
@Column(name = "first_name")
private String firstName;
@NotEmpty
@Column(name = "last_name")
private String lastName;
@NotNull(message = "enter a date")
@Temporal(TemporalType.DATE)
@Column(name = "birth_date")
@DateTimeFormat(pattern = "dd/MM/yyyy")
private Date birthDate;
@CreationTimestamp
@Temporal(TemporalType.DATE)
@Column(name = "first_assesment")
@DateTimeFormat(pattern = "dd/MM/yyyy")
private Date createdP;
@Column(name = "sex")
private String sex;
@NotNull
@Email
@Column(name = "email")
private String email;
@OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH,
CascadeType.DETACH })
@JoinColumn(name="patient_id")
private List<BMI> bmis;
//Getters Setters
}
这是 DAO 对象(mySQL 中的表有一个 Patient_id 列):
@Repository
public class BMIImpl implements BMIDAO {
@Autowired
private SessionFactory sf;
...
@SuppressWarnings("unchecked")
@Transactional
public List<BMI> listBMIpat(int patId){
Session s = this.sf.getCurrentSession();
List<BMI> bmis = (List<BMI>) s.createSQLQuery("Select * from BMI B where B.patient_id = "+patId).list();
return bmis;
}
...
}
服务对象:
@Service
@Transactional
public class BMIServiceImpl implements BMIService {
@Autowired
private BMIDAO bdao;
@Override
@Transactional
public List<BMI> getBMIbyPatient(int patId) {
return bdao.listBMIpat(patId);
}
...
}
这是 Controller :
@Controller
@RequestMapping("/bmi/{patId}")
public class BMIController {
@SuppressWarnings("unused")
private static final Logger logger = Logger.getLogger(BMIController.class);
public BMIController() {
System.out.println("BMIController()");
}
@Autowired
private BMIService bs;
@RequestMapping(method = RequestMethod.GET)
public ModelAndView listBMIs(@PathVariable("patId") Integer patId, ModelAndView model) throws IOException {
List<BMI> bmis = bs.getBMIbyPatient(patId);
model.addObject("listBMIs", bmis);
model.setViewName("viewBMIs");
return model;
}
...
}
这是页面:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<...>
<table border="1">
<tr>
<th>Created</th>
<th>Weight</th>
<th>Height</th>
<th>BMI</th>
<th>Action</th>
<tr>
<c:forEach var="bmi" items="${listBMIs}">
<tr>
<td><fmt:formatDate pattern="dd/MM/yyyy" value="${bmi.createdW}" /></td>
<td>${bmi.weight}</td>
<td>${bmi.height}</td>
<td>${bmi.bmi}</td>
<td><a href="editBMI?bmiId=${bmi.bmiId}">Edit</a> <a
href="deleteBMI?bmiId=${bmi.bmiId}">Delete</a></td>
</tr>
</c:forEach>
</table>
</div>
</body>
</html>
错误:
SEVERE: Servlet.service() for servlet [jsp] threw exception
java.lang.NumberFormatException: For input string: "createdW"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at javax.el.ArrayELResolver.coerce(ArrayELResolver.java:144)
at javax.el.ArrayELResolver.getValue(ArrayELResolver.java:61)
at org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:110)
at org.apache.el.parser.AstValue.getValue(AstValue.java:169)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:190)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:944)
at org.apache.jsp.WEB_002dINF.pages.viewBMIs_jsp._jspx_meth_fmt_005fformatDate_005f0(viewBMIs_jsp.java:254)
at org.apache.jsp.WEB_002dINF.pages.viewBMIs_jsp._jspx_meth_c_005fforEach_005f0(viewBMIs_jsp.java:198)
at org.apache.jsp.WEB_002dINF.pages.viewBMIs_jsp._jspService(viewBMIs_jsp.java:150)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:728)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:470)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:395)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:316)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1228)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1011)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:955)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:660)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:808)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Oct 11, 2019 5:36:37 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [spring] in context with path [/LymphodemaProjectMVC] threw exception [java.lang.NumberFormatException: For input string: "createdW"] with root cause
java.lang.NumberFormatException: For input string: "createdW"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at javax.el.ArrayELResolver.coerce(ArrayELResolver.java:144)
at javax.el.ArrayELResolver.getValue(ArrayELResolver.java:61)
at org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:110)
at org.apache.el.parser.AstValue.getValue(AstValue.java:169)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:190)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:944)
at org.apache.jsp.WEB_002dINF.pages.viewBMIs_jsp._jspx_meth_fmt_005fformatDate_005f0(viewBMIs_jsp.java:254)
at org.apache.jsp.WEB_002dINF.pages.viewBMIs_jsp._jspx_meth_c_005fforEach_005f0(viewBMIs_jsp.java:198)
at org.apache.jsp.WEB_002dINF.pages.viewBMIs_jsp._jspService(viewBMIs_jsp.java:150)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:728)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:470)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:395)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:316)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1228)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1011)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:955)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:660)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:808)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
我对患者表进行了完全相同的设置,但当我运行项目的该部分时,我没有收到任何异常消息。
编辑:我删除了 mySQL 中表内的信息,现在页面可以正确加载。我不知道为什么会这样。
编辑:我发现日期在数据库中的存储方式不同。然而,对于患者来说,它以一种格式存储,而对于bmi,则以不同的格式存储。这意味着当它尝试加载日期时,它不会将其视为日期并给出错误。我不知道为什么会发生这种情况。
最佳答案
检查您是否在页面顶部添加了此行。
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
关于java.lang.NumberFormatException : for input string {Date}. Spring MVC 我无法识别错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58349233/
我正在尝试使用 Integer.parseInt(simNumber) 将 String 转换为 int,但我收到错误消息。如何将 String 转换为 int?我在网上搜索了一下,找到了Intege
每次我尝试启动我的代码时,我总是遇到同样的错误: java.lang.NumberFormatException: For input string: "x" at java.lang.Numbe
在检查我的错误处理代码时偶然发现了这个。当您调用 Integer.parseInt(null) 时,Java 抛出 NumberFormatException 而 Float.parseFloat(n
如果有人可以看看我在 Selenium 方面遇到的问题。我尝试使用以下方法访问上述计算器中的结果: public String getAttributeValue(WebElement element
嗯,我很无聊,所以我想做一个二进制>十进制转换器。我将转换器的上限设置为 30 位数字 (1073741823) 或 (0111111111111111111111111111111)。我遇到的问题是
在以下代码中,Clojure (1.2) 打印出错误消息: (try (let [value "1,a"] (map #(Integer/parseInt %) (.split value
String str="123456.7855456677"; ParsePosition parsePosition = new ParsePosition(0); NumberFormat num
代码: String myVar = "1255763710960"; int myTempVar=0; try { myTempVar = Integer.valueOf(myVar); }
我在NumberFormatException代码中收到Grails错误,该错误是将电影分类到数据库中。该错误表明它来自cron插件。我已经完成了研究,并且一直在尝试使用NumberFormatExc
我在将字符串解析为原语时遇到问题。 File file1 = new File("bankData.txt"); Scanner sc = new Scanner(fi
所以我试图从日期列表中查找最新日期,但我不断收到 NumberFormatException。有什么办法可以解决这个问题吗? import java.util.*; public class Date
如果使用变量 bin1 它不会转换,但是如果我用 bin2 替换参数,它似乎可以工作。 我尝试使用 long 而不是 int。还是一样。 public class Test{ public s
我正在尝试找出如何在代码中捕获数字格式异常错误,这样如果用户在字符串中输入字母并且我的程序尝试将其解析为 int 我的程序将不会抛出错误而是停止并返回一个 boolean 值。我还试图了解,如果 tr
该程序的本质目的是将学生信息写入文件并从同一文件中读取。该程序包括一个 if 语句,用于判断学生是否处于良好信誉或留校察看状态,每个语句都有各自的文件(goodstand.txt 和 probatio
我正在用 Python/WLST 编写代码,以自动连接、启动和停止 weblogic 中的托管服务器。当我启动 Python 时,出现以下错误。 异常的含义是什么?我该如何解决它? Initializ
这是我的代码: public void setAreaAccessPoints(){ String mac = "",essid = "",status = ""; int stre
我正在用 Java 开发一个应用程序,发现了这个奇怪的行为: 如果通过控制面板将区域设置格式设置为匈牙利语(系统默认值),我会收到此异常,但如果我将其设置为英语格式,则它可以正常工作。也适用于虚拟 M
我正在尝试制作一个计算器应用程序,但不幸的是我无法解析字符串。 应用程序接受输入并将其显示在 EditText et2 中。当按下“等于”键时,计算器将执行以下工作。 et2 = (EditText)
我有一个文件,其中包含许多电影标题及其年份、5 星评级和长度。我正在尝试读取该文件并将标题、年份、评级和长度存储为变量。我遇到的问题是在我的检索年份的代码中。该代码可以编译,但在运行时,当它到达具有多
我正在解决亚马逊 Interview Street 网站上的 Connected Sets 问题 https://amazon.interviewstreet.com/challenges我的代码对于
我是一名优秀的程序员,十分优秀!