這是我在Eror JSP頁面無法從類型轉換[java.lang.String中]鍵入[@ javax.persistence.Id @ javax.persistence.GeneratedValue INT]
Servlet.service() for servlet jsp threw exception
java.lang.NumberFormatException: For input string: "${c.catId}"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.valueOf(Unknown Source)
at org.springframework.util.NumberUtils.parseNumber(NumberUtils.java:208)
at org.springframework.core.convert.support.StringToNumberConverterFactory$StringToNumber.convert(StringToNumberConverterFactory.java:62)
at org.springframework.core.convert.support.StringToNumberConverterFactory$StringToNumber.convert(StringToNumberConverterFactory.java:49)
at org.springframework.core.convert.support.GenericConversionService$ConverterFactoryAdapter.convert(GenericConversionService.java:436)
at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:37)
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:203)
at org.springframework.core.convert.support.ConvertingPropertyEditorAdapter.setAsText(ConvertingPropertyEditorAdapter.java:59)
at org.springframework.web.servlet.tags.form.SelectedValueComparator.exhaustiveCompare(SelectedValueComparator.java:173)
at org.springframework.web.servlet.tags.form.SelectedValueComparator.isSelected(SelectedValueComparator.java:98)
at org.springframework.web.servlet.tags.form.OptionTag.isSelected(OptionTag.java:238)
at org.springframework.web.servlet.tags.form.OptionTag.renderOption(OptionTag.java:202)
at org.springframework.web.servlet.tags.form.OptionTag.renderFromBodyContent(OptionTag.java:151)
at org.springframework.web.servlet.tags.form.AbstractHtmlElementBodyTag.doEndTag(AbstractHtmlElementBodyTag.java:66)
at org.apache.jsp.WEB_002dINF.views.ProductForm_jsp._jspService(ProductForm_jsp.java:333)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:716)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:466)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:391)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318)
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:1286)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1041)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:984)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1533)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1489)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Aug 03, 2017 2:06:22 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/frontend] threw exception [org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@javax.persistence.Id @javax.persistence.GeneratedValue int] for value '${c.catId}'; nested exception is java.lang.NumberFormatException: For input string: "${c.catId}"] with root cause
java.lang.NumberFormatException: For input string: "${c.catId}"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.valueOf(Unknown Source)
at org.springframework.util.NumberUtils.parseNumber(NumberUtils.java:208)
at org.springframework.core.convert.support.StringToNumberConverterFactory$StringToNumber.convert(StringToNumberConverterFactory.java:62)
at org.springframework.core.convert.support.StringToNumberConverterFactory$StringToNumber.convert(StringToNumberConverterFactory.java:49)
at org.springframework.core.convert.support.GenericConversionService$ConverterFactoryAdapter.convert(GenericConversionService.java:436)
at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:37)
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:203)
at org.springframework.core.convert.support.ConvertingPropertyEditorAdapter.setAsText(ConvertingPropertyEditorAdapter.java:59)
at org.springframework.web.servlet.tags.form.SelectedValueComparator.exhaustiveCompare(SelectedValueComparator.java:173)
at org.springframework.web.servlet.tags.form.SelectedValueComparator.isSelected(SelectedValueComparator.java:98)
at org.springframework.web.servlet.tags.form.OptionTag.isSelected(OptionTag.java:238)
at org.springframework.web.servlet.tags.form.OptionTag.renderOption(OptionTag.java:202)
at org.springframework.web.servlet.tags.form.OptionTag.renderFromBodyContent(OptionTag.java:151)
at org.springframework.web.servlet.tags.form.AbstractHtmlElementBodyTag.doEndTag(AbstractHtmlElementBodyTag.java:66)
at org.apache.jsp.WEB_002dINF.views.ProductForm_jsp._jspService(ProductForm_jsp.java:333)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:716)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:466)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:391)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318)
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:1286)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1041)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:984)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1533)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1489)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
這是我的產品形式在那裏我'點擊賣出fasgen
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="a" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Product Form</title>
</head>
<body>
<jsp:include page="Header.jsp"></jsp:include>
<!-- Product insertion -->
<%-- <a:url var="url" value='/saveproduct' /> --%>
<%-- <spring:url value='/saveproduct' var="url"/> --%>
<form:form action="saveproduct" commandName="product">
<div class="form-group">
<form:hidden path="pid" class="form-control" />
</div>
<div class="form-group">
Enter Model Details:
<form:input path="modelDetails" class="form-control" />
</div>
<div class="form-group">
Enter Product Name:
<form:input path="productname" class="form-control" />
</div>
<div class="form-group">
Enter Price:
<form:input path="price" class="form-control" />
</div>
<div class="form-group">
Enter Quantity:
<form:input path="qty" class="form-control" />
</div>
<div class="form-group">
Enter Patter:
<form:input path="pattern" class="form-control" />
</div>
<div class="form-group">
Enter Style Type:
<form:input path="styleType" class="form-control" />
</div>
<div class="form-group">
Enter Wear Type
<form:input path="weartype" class="form-control" />
</div>
<div class="form-group">
Enter Style Code:
<form:input path="styleCode" class="form-control" />
</div>
<div class="form-group">
Enter Colour:
<form:input path="color" class="form-control" />
</div>
<div class="form-group">
Enter Fabric Care:
<form:input path="fabriccare" class="form-control" />
</div>
<div class="form-group">
Type:
<form:input path="type" class="form-control" />
</div>
<div class="form-group">
Sleeve:
<form:input path="sleeve" class="form-control" />
</div>
<div class="form-group">
Enter Neck Type:
<form:input path="necktype" class="form-control" />
</div>
<div class="form-group">
Enter Pockets:
<form:input path="pockets" class="form-control" />
</div>
<div class="form-group">
Enter Pockets:
<form:input path="price" class="form-control" />
</div>
<div class="form-group">
Ideal For:
<form:select path="category.catId">
<a:forEach items="${categories} " var="c" >
<form:option value="${c.catId}">${c.idealfor }</form:option>
</a:forEach>
</form:select>
</div>
<div class="form-group">
<input type="submit" value="Add Product">
</div>
</form:form>
<jsp:include page="Footer.jsp"></jsp:include>
</body>
</html>
我控制器產品
package com.project.controllers;
import java.util.List;
//import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import com.project.service.ProductService;
import com.project.model.Category;
//import com.project.service.ProductServiceImpl;
import com.project.model.Product;
@Controller
public class ProductController {
@Autowired
private ProductService productService;
@RequestMapping(value="/ProductForm")
public String productForm(Model model) {
List<Category> categories=productService.getAllCategory();
model.addAttribute("categories",categories);
model.addAttribute("product", new Product());
System.out.println(categories);
return "ProductForm";
}
@RequestMapping(value="/saveproduct")
public String saveProduct(@ModelAttribute(name="product") Product product,BindingResult result){
productService.addProduct(product);
return "Home";
}
}
,這我的模型
package com.project.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
@Entity
public class Product {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int pid;
private int qty;
private String productname;
private String modelDetails;
private String pattern;
private String styleType;
private String weartype;
private String styleCode;
private String color;
private String fabriccare;
private String type;
private String sleeve;
private String necktype;
private int pockets;
private double price;
@ManyToOne
@JoinColumn(name="catId")
private Category category;
public int getPid() {
return pid;
}
public int getQty() {
return qty;
}
public String getProductname() {
return productname;
}
public String getModelDetails() {
return modelDetails;
}
public String getPattern() {
return pattern;
}
public String getStyleType() {
return styleType;
}
public String getWeartype() {
return weartype;
}
public String getStyleCode() {
return styleCode;
}
public String getColor() {
return color;
}
public String getFabriccare() {
return fabriccare;
}
public String getType() {
return type;
}
public String getSleeve() {
return sleeve;
}
public String getNecktype() {
return necktype;
}
public int getPockets() {
return pockets;
}
public double getPrice() {
return price;
}
public Category getCategory() {
return category;
}
public void setPid(int pid) {
this.pid = pid;
}
public void setQty(int qty) {
this.qty = qty;
}
public void setProductname(String productname) {
this.productname = productname;
}
public void setModelDetails(String modelDetails) {
this.modelDetails = modelDetails;
}
public void setPattern(String pattern) {
this.pattern = pattern;
}
public void setStyleType(String styleType) {
this.styleType = styleType;
}
public void setWeartype(String weartype) {
this.weartype = weartype;
}
public void setStyleCode(String styleCode) {
this.styleCode = styleCode;
}
public void setColor(String color) {
this.color = color;
}
public void setFabriccare(String fabriccare) {
this.fabriccare = fabriccare;
}
public void setType(String type) {
this.type = type;
}
public void setSleeve(String sleeve) {
this.sleeve = sleeve;
}
public void setNecktype(String necktype) {
this.necktype = necktype;
}
public void setPockets(int pockets) {
this.pockets = pockets;
}
public void setPrice(double price) {
this.price = price;
}
public void setCategory(Category category) {
this.category = category;
}
}
分類模型
package com.project.model;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import java.util.List;
@Entity
public class Category {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int catId;
private String idealfor;
@OneToMany(cascade=CascadeType.ALL,mappedBy="category")
private List<Product> product;
public int getCatId() {
return catId;
}
public String getIdealfor() {
return idealfor;
}
public List<Product> getProduct() {
return product;
}
public void setCatId(int catId) {
this.catId = catId;
}
public void setIdealfor(String idealfor) {
this.idealfor = idealfor;
}
public void setProduct(List<Product> product) {
this.product = product;
}
}
現在我就在headear.jsp上Fashgen賣出時點擊一下,它顯示這個exception.I有諸多檢查解決方案,但在最後,我需要幫助形成你,請讓我離開這個問題
我加入類實體的太
你確定類別ID是正確的,正確的進賬?您的類別ID不正確。它的格式不正確,不是數字。你還可以發佈你的'Category'實體嗎? –
在我看來,(預期的)表達式「$ {c.id}」在jsp的上下文中不是「正確」評估的,而是按字面上的「$ {c.id}」傳遞給控制器的。我只能建議你弄清楚爲什麼會發生這種情況。 – gtosto
我已將類別添加到問題 – Karangupta