I am using Spring MVC. I am making a dummy project in which I am taking categories of clothes from database using hibernate and add it to the modelAndView(add as list) attribute and send it to the view page. In view page I have to show the categories.But I am not able to get the value. Please my when the view page is getting called I am getting number format exception.
This is my controller code.
@RequestMapping(value = "/insproduct")
public ModelAndView insertProduct(HttpServletResponse response)
throws IOException {
List<Catogories> cat = categories.selectCategories();
ModelAndView mav = new ModelAndView("admin/insproduct");
mav.addObject("cato", cat);
return mav;
}
The Controller call to my Jsp page. This is my jsp page.
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="online.model.Catogories" %>
<anyxmlelement xmlns:c="http://java.sun.com/jsp/jstl/core">
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<div style="text-align: center;">
<div style="box-sizing: border-box; display: inline-block; width: auto; max-width: 480px; background-color: #FFFFFF; border: 2px solid #0361A8; border-radius: 5px; box-shadow: 0px 0px 8px #0361A8; margin: 50px auto auto;">
<div style="background: #0361A8; border-radius: 5px 5px 0px 0px; padding: 15px;"><span style="font-family: verdana,arial; color: #D4D4D4; font-size: 1.00em; font-weight:bold;">ENTER THE PRODUCT</span></div>
<div style="background: ; padding: 15px">
<style type="text/css" scoped>
<select style="background: ; padding: 15px">
<select style="text-align: left;">
td { text-align:left; font-family: verdana,arial; color: #064073; font-size: 1.00em; }
input { border: 1px solid #CCCCCC; border-radius: 5px; color: #666666; display: inline-block; font-size: 1.00em; padding: 5px; width: 100%; }
input[type="button"], input[type="reset"], input[type="submit"] { height: auto; width: auto; cursor: pointer; box-shadow: 0px 0px 5px #0361A8; float: right; margin-top: 10px; }
table.center { margin-left:auto; margin-right:auto; }
.error { font-family: verdana,arial; color: #D41313; font-size: 1.00em; }
</style>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form name="input" action="demo_form_action.asp" method="get">
<br>
PRODUCT ID: <input type="text" name="product_id"><br>
PRODUCT NAME: <input type="text" name="product_name"><br>
PRODUCT BUY PRICE: <input type="text" name="product_buy_price"><br>
PRODUCT SELL PRICE: <input type="text" name="product_sell_price"><br>
<c:forEach items="${cat}" var="cato">
<tr>
<td>${cato.getCatogories_name}</td>
</tr>
</c:forEach>
<br>
<input type="radio" name="sex" value="male">Male
<input type="radio" name="sex" value="female">Female
<br>
<input type="radio" name="age_group" value="adult">adult
<input type="radio" name="age_group" value="child">child
<br>
PRODUCT SIZE: <input type="text" name="product_detail_size"><br>
PRODUCT COLOR: <input type="text" name="pproduct_image"><br>
PRODUCT DISCOUNT: <input type="text" name="product_discount"><br>
<input type="button" value="ENTER" align="right" width="48" height="48">
</form>
</body>
</html>
This is my POJO class from which which I am getting values. Please help me.
package online.model;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
@Entity
@Table(name="product_catogories")
public class Catogories {
@Id
private int catogories_id;
@Column(name="catogories_name")
private String catogories_name;
@ManyToMany(mappedBy = "catogories")
private Set<Product> products;
public Set<Product> getProducts() {
return products;
}
public void setProducts(Set<Product> products) {
this.products = products;
}
public int getCatogories_id() {
return catogories_id;
}
public void setCatogories_id(int catogories_id) {
this.catogories_id = catogories_id;
}
public String getCatogories_name() {
return catogories_name;
}
public void setCatogories_name(String catogories_name) {
this.catogories_name = catogories_name;
}
}
This is my DAO Class Implementation
package online.deo;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import online.model.Catogories;
import online.services.CategoriesServices;
@Transactional
@Repository
@Component
public class CategoriesServicesImpls implements CategoriesServices {
CategoriesServicesImpls() {
}
@Autowired
private SessionFactory sessionFactory;
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
@Override
public int insertCategories() {
return 0;
}
@Override
public int updateCategories() {
return 0;
}
@Override
public int deleteCategories() {
return 0;
}
@Override
@Transactional(readOnly = true)
public List<Catogories> selectCategories() {
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
Query query = session.createQuery("from Catogories");
return query.list();
}
}
And this is what I am getting error. I have trying to under the error but It is only giving that I have numberformat exception.I dont know by it is giving the error
Stacktrace:] with root cause
java.lang.NumberFormatException: For input string: "getCatogories_name"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.Integer.parseInt(Integer.java:527)
at javax.el.ListELResolver.coerce(ListELResolver.java:163)
at javax.el.ListELResolver.getValue(ListELResolver.java:51)
at org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:104)
at org.apache.el.parser.AstValue.getValue(AstValue.java:183)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:967)
at org.apache.jsp.WEB_002dINF.jsp.admin.insproduct_jsp._jspService(insproduct_jsp.java:104)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1157)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:927)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Thanks for help.and I am also getting confused in using foreach loop in jstl.