After upgrading Spring Boot from 2.2.4 to 2.2.5 in my application, I get the following exception when uploading files with a multipart/form-data form:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly] with root cause
org.apache.commons.fileupload.MultipartStream$MalformedStreamException: Stream ended unexpectedly
at org.apache.commons.fileupload.MultipartStream$ItemInputStream.makeAvailable(MultipartStream.java:1033)
at org.apache.commons.fileupload.MultipartStream$ItemInputStream.read(MultipartStream.java:931)
at java.io.InputStream.read(InputStream.java:101)
at org.apache.commons.fileupload.util.Streams.copy(Streams.java:98)
at org.apache.commons.fileupload.util.Streams.copy(Streams.java:68)
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:346)
at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:113)
at org.springframework.web.multipart.commons.CommonsMultipartResolver.parseRequest(CommonsMultipartResolver.java:159)
at org.springframework.web.multipart.commons.CommonsMultipartResolver.resolveMultipart(CommonsMultipartResolver.java:143)
at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1178)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1012)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:665)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:750)
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:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:126)
...
The form looks like this:
<form id="addPhotosForm" method="post" action="/images/add" enctype="multipart/form-data">
<div class="row">
<div class="col-sm-4">
<div class="input-group">
<input type="file" name="images" multiple>
</div>
</div>
<div class="col-sm-6 pull-left">
<input name="submit" type="submit" value="Save">
</div>
</div>
</form>
And the controller looks like this:
#RequestMapping(value = "/images/add")
public String addPhoto(#RequestParam(value = "images", required = false) MultipartFile[] multipartImages) {
//...
}
Works fine after updating Spring Boot to version 2.2.6.
Related
I am new in jstl and i try to use jstl core and sql to fetch data from database.
when I use java code i get data of type com.mysql.cj.jdbc.result.ResultSetImpl.
when I use sql:query of jstl i get org.apache.taglibs.standard.tag.common.sql.ResultImpl
and <c:forEach>'s items doesn't accept both of them.
Java code:
ResultSet result ;
try {
Class.forName(driver);
Connect = DriverManager.getConnection(url+dbName, userNameDB, dbpassword);
Statement st = Connect.createStatement();
result = st.executeQuery("SELECT * FROM questions");
}catch (Exception e) {
System.out.print(e);
}
jstl:
<sql:setDataSource var="myDB" driver="com.mysql.jdbc.Driver" user="root" password="" url="jdbc:mysql://localhost/exposerjstl" />
<sql:query var="questions" dataSource="${myDB}" >
SELECT * FROM questions;
</sql:query>
<c:forEach var="row" items="${questions}">
<div><c:out value="${row.question}" /><br>
</c:forEach>
the result is:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:611)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:490)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:378)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:326)
javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
examenServlet.doGet(examenServlet.java:72)
javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
javax.servlet.ServletException: javax.servlet.jsp.JspTagException: Don't know how to iterate over supplied "items" in <forEach>
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:664)
org.apache.jsp.views.home_jsp._jspService(home_jsp.java:217)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:71)
javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:467)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:378)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:326)
javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
examenServlet.doGet(examenServlet.java:72)
javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
javax.servlet.jsp.JspTagException: Don't know how to iterate over supplied "items" in <forEach>
org.apache.taglibs.standard.tag.common.core.ForEachSupport.toForEachIterator(ForEachSupport.java:274)
org.apache.taglibs.standard.tag.common.core.ForEachSupport.supportedTypeForEachIterator(ForEachSupport.java:238)
org.apache.taglibs.standard.tag.common.core.ForEachSupport.prepare(ForEachSupport.java:155)
javax.servlet.jsp.jstl.core.LoopTagSupport.doStartTag(LoopTagSupport.java:256)
org.apache.jsp.views.home_jsp._jspx_meth_c_005fforEach_005f0(home_jsp.java:326)
org.apache.jsp.views.home_jsp._jspService(home_jsp.java:182)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:71)
javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:467)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:378)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:326)
javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
examenServlet.doGet(examenServlet.java:72)
javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Note The full stack trace of the root cause is available in the server logs.
Apache Tomcat/9.0.43
In your JSTL version the type of the questions attribute is Result. You cannot iterate over it, but you can iterate over Result#getRows(), so just replace ${questions} with ${questions.rows}:
<sql:setDataSource var="myDB" driver="com.mysql.jdbc.Driver"
user="root" password="" url="jdbc:mysql://localhost/exposerjstl" />
<sql:query var="questions" dataSource="${myDB}" >
SELECT * FROM questions;
</sql:query>
<div>
<c:forEach var="row" items="${questions.rows}">
<c:out value="${row.question}" />
<br />
</c:forEach>
</div>
As remarked by BalusC, the <sql:...> tags are mostly for prototyping. In production you should create the collection in Java code, set it as a request attribute and call the JSP template.
I want to create form in jsp based on how many items are in HashMap which I pass to the view.
So first I've created a form which gives me a HashMap of items, then in second form I want give user opportunity to change result of first form operations. In second form I've got HashMap attribute set by my controller and I've tried to do something like this:
Controller:
package com.capc.controller;
import com.capc.model.ConferenceTimetable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
#Controller
public class CapcController {
#RequestMapping(value = "/conferenceAdvertParser", method = RequestMethod.GET)
public ModelAndView showConferenceAdvertParser() {
return new ModelAndView("conferenceAdvertParser", "command", new ConferenceTimetable());
}
#RequestMapping(value = "/parseConferenceAdvert", method = RequestMethod.POST)
public String addEmployee(#ModelAttribute("SpringWeb") ConferenceTimetable ct, ModelMap model) {
ct.parseConferenceAdvert();
model.addAttribute("conferenceTimetable", ct.getConferenceTimetable());
return "conferenceEventEditor";
}
}
Second JSP form:
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<%# taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>Title</title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
<link rel='stylesheet' href='webjars/bootstrap/3.2.0/css/bootstrap.min.css'>
</head>
<body>
<form:form method="POST" action="/">
<table border="1">
<c:forEach items="${conferenceTimetable}" var="entry">
<tr>
<td><form:label path="${entry.key}">test label</form:label></td>
<td><form:input path="${entry.key}"></form:input></td>
</tr>
</c:forEach>
<tr>
<td colspan="2">
<input type="submit" value="Submit"/>
</td>
</tr>
</table>
</form:form>
</body>
</html>
And I've got error while second JSP page is created. I don't have any other idea how to do this, any ideas?
Error:
HTTP Status 500 – Internal Server Error
Type Exception Report
Message An exception occurred processing JSP page [/conferenceEventEditor.jsp] at line [30]
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
org.apache.jasper.JasperException: An exception occurred processing JSP page [/conferenceEventEditor.jsp] at line [30]
27:
28:
29: <tr>
30: <td><form:label path="a">test label</form:label></td>
31: <td><form:input path="a" value="dupa"></form:input></td>
32: <%--<td>${entry.value.eventDate}</td>--%>
33: <%--<td>${entry.value.eventDescription}</td>--%>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:584)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1243)
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1027)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871)
javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute
org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:144)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:168)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:188)
org.springframework.web.servlet.tags.form.LabelTag.autogenerateFor(LabelTag.java:130)
org.springframework.web.servlet.tags.form.LabelTag.resolveFor(LabelTag.java:120)
org.springframework.web.servlet.tags.form.LabelTag.writeTagContent(LabelTag.java:90)
org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:84)
org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80)
org.apache.jsp.conferenceEventEditor_jsp._jspx_meth_form_005flabel_005f0(conferenceEventEditor_jsp.java:346)
org.apache.jsp.conferenceEventEditor_jsp._jspx_meth_c_005fforEach_005f0(conferenceEventEditor_jsp.java:291)
org.apache.jsp.conferenceEventEditor_jsp._jspx_meth_form_005fform_005f0(conferenceEventEditor_jsp.java:206)
org.apache.jsp.conferenceEventEditor_jsp._jspService(conferenceEventEditor_jsp.java:152)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1243)
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1027)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871)
javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Note The full stack trace of the root cause is available in the server logs.
Apache Tomcat/8.5.24
Finally I change JSP to thymeleaf. You can generate that kind of field by setting an argument like
th:field="*{conferenceTimetableMap[__${event.key}__]}"
Once I click on a anchor tag on my jsp page, it perfectly works but the following exception will be thrown in console, based on this answer, I removed the jap-api*.jar files from my dependencies folder but the application still throws the exception.
WARNING: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at org.apache.jsp.products.ProductShow_jsp._jspx_meth_c_if_1(ProductShow_jsp.java:211)
at org.apache.jsp.products.ProductShow_jsp._jspService(ProductShow_jsp.java:119)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:875)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:739)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:695)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:626)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:977)
at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:701)
at org.apache.tiles.request.jsp.JspRequest.doInclude(JspRequest.java:123)
at org.apache.tiles.request.AbstractViewRequest.dispatch(AbstractViewRequest.java:47)
at org.apache.tiles.request.render.DispatchRenderer.render(DispatchRenderer.java:45)
at org.apache.tiles.request.render.ChainedDelegateRenderer.render(ChainedDelegateRenderer.java:68)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:259)
at org.apache.tiles.TilesContainerWrapper.render(TilesContainerWrapper.java:108)
at org.apache.tiles.template.InsertAttributeModel.renderAttribute(InsertAttributeModel.java:188)
at org.apache.tiles.template.InsertAttributeModel.execute(InsertAttributeModel.java:132)
at org.apache.tiles.jsp.taglib.InsertAttributeTag.doTag(InsertAttributeTag.java:299)
at org.apache.jsp.baseLayout_jsp._jspx_meth_tiles_insertAttribute_3(baseLayout_jsp.java:166)
at org.apache.jsp.baseLayout_jsp._jspService(baseLayout_jsp.java:93)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:875)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:739)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:575)
at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:546)
at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:428)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:378)
at org.apache.tiles.request.servlet.ServletRequest.forward(ServletRequest.java:265)
at org.apache.tiles.request.servlet.ServletRequest.doForward(ServletRequest.java:228)
at org.apache.tiles.request.AbstractClientRequest.dispatch(AbstractClientRequest.java:57)
at org.apache.tiles.request.render.DispatchRenderer.render(DispatchRenderer.java:45)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:259)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:397)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:238)
at org.apache.tiles.TilesContainerWrapper.render(TilesContainerWrapper.java:103)
at org.apache.tiles.impl.mgmt.CachingTilesContainer.render(CachingTilesContainer.java:126)
.....
WARNING: Servlet.service() for servlet jsp threw exception
java.io.IOException: JSPException including path '/products/Product.jsp'.
at org.apache.tiles.request.servlet.ServletUtil.wrapServletException(ServletUtil.java:61)
at org.apache.tiles.request.jsp.JspRequest.doInclude(JspRequest.java:125)
at org.apache.tiles.request.AbstractViewRequest.dispatch(AbstractViewRequest.java:47)
at org.apache.tiles.request.render.DispatchRenderer.render(DispatchRenderer.java:45)
Code
<div id="product">
<table>
<tbody>
<tr><td>ID:${product.id}</td></tr>
.....
</tbody>
</table>
<sec:authorize access="hasAnyRole('ROLE_ADMIN')">
<c:if test="${product.available}">
<s:if test="%{availability > 1}">
Remove
</s:if>
<s:else>
<c:if test="${cookie.containsKey('id')}">
Add
</c:if>
<c:if test="${!cookie.containsKey('id')}">
index
</c:if>
</s:else>
</c:if>
</sec:authorize>
</div>
Remove and Add are associated to their own javascript functions, both functions perfectly work but the exceptions will be thrown and after returning from javascript functions the page shows correct results.
You can actually figure this out yourself with a little work. JSPs are compiled into servlets and the source code can be found under your web server's works folder. Generally, find the 'work' folder and then drill down thru the packages, which for Tomcat is usually org.apache.... (sorry can't remember the exact and this machine doesn't have Tomcat installed). Just drill down and you should find ProductShow_jsp.java source code. Goto the line number specified and you can generally figure out the reason for the exception.
Please check if the below suggestions gets rid of the error:
a) Check if product.id or product.ID is defined
b) Check if the attribute name is correct for product.available
c) Add the closing tag for <c:if test="${product.available}">
I am trying to implement Spring Pagination in my (Spring MVC / Hibernate / MySQL) project under Eclipse STS so I've followed the example in [A Pagination Technique Using Spring][1] since I found it recommended here in Stackoverflow in many answers to similar questions. Now I have a question and a problem:
Question: How can I import the pagination tag file into my project? Specially that I don't see any Tag folder under my project WEB-INF folder?
Problem: I am facing some trouble as each time I try to build / run the project I get error:
java.lang.ClassNotFoundException: org.springframework.web.context.support.StandardServletEnvironment
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at org.springframework.web.servlet.HttpServletBean.(HttpServletBean.java:90)
at org.springframework.web.servlet.FrameworkServlet.(FrameworkServlet.java:211)
at org.springframework.web.servlet.DispatcherServlet.(DispatcherServlet.java:303)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:357)
at java.lang.Class.newInstance(Class.java:310)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:138)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5123)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5407)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1114)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1672)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)
I have double checked my code and I don't see what might be wrong. So can anyone please tell me what I might be doing wrong?
Controller:
public String listVolDisc(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
List searchResults = ivoldiscservice.getAllVolDisc();
PagedListHolder pagedListHolder = new PagedListHolder(searchResults);
int page = ServletRequestUtils.getIntParameter(request, "p", 0);
pagedListHolder.setPage(page);
int pageSize = 10;
pagedListHolder.setPageSize(pageSize);
model.addAttribute("pagedListHolder", pagedListHolder);
return "VolDiscount";
}
JSP:
<c:url value="/paging.do" var="pagedLink">
<c:param name="action" value="list"/>
<c:param name="p" value="~"/>
</c:url>
<div class="section">
<h2 class="section_title">Volume Discounts</h2>
<tg:paging pagedListHolder="${pagedListHolder}" pagedLink="${pagedLink}"/>
<div class="table">
<div class="table_header">
<div class="cell">ID</div>
<div class="cell">From</div>
<div class="cell">To</div>
<div class="cell">Discount</div>
</div>
<%-- <c:forEach var="voldiscount" items="${voldiscountList}"> --%>
<c:forEach var="voldiscount" items="${pagedListHolder}">
<div class="table_row">
<div class="cell important">${voldiscount.id}</div>
<div class="cell">${voldiscount.rangeStarts}</div>
<div class="cell">${voldiscount.rangeEnds}</div>
<div class="cell">${voldiscount.discount}</div>
</div>
</c:forEach>
</div><!-- .table -->
<tg:paging pagedListHolder="${pagedListHolder}" pagedLink="${pagedLink}"/>
</div><!-- .section -->
DAO:
public List<VolumeDiscount> getAllVolDisc() {
return sessionfactory.getCurrentSession().createQuery("from VolumeDiscount v").list();
}
Thanks for your time
It seems you have missing dependency: spring-web.
I want to call my method getSelectedLayouts in my jsp page, where the method is
public Iterable<Layouts> getSelectedLayouts(String Subject){
Session sess=getCurrentSession();
return sess.createCriteria(Layouts.class, Subject).list();
}
Inside class LayoutManager. I passed LayoutManager into my jsp page using a Spring Bean
<custom:useSpringBean var="layoutManager" bean="LayoutManager">
the jsp page asks for the subject
<form method="post">
<label for="subjectName">SubjectName:</label>
<input type="text" name="subjectName" size="50" id="subjectName">
<input class="button" type="submit" value="Search Layout" name="submit">
</form>
Which I then pass to
<jsp:useBean id="subjectName" class="LayoutManager">
<c:if test="${param.submit!=null}">
(here's where I want to call my getSelectedLayouts method)
</c:if>
I've been trying with scriplets, including variations of
<jsp:setProperty name="layout" property="*"/>
((LayoutManager)pageContext.getAttribute("layoutManager")).getSelectedLayout((Layouts)pageContext.getAttribute("layout"));
or just
<jsp:setProperty name="layout" property="*"/>
list<Layouts> = LayoutManager.getSelectedLayouts(layout);
Where Layouts is my object class
Please tell me if I need to give any other information
Edit: When I try
LayoutManager layoutManager = new LayoutManager();
String subjectNa = request.getParameter("subjectName");
Iterable<Layouts> bla = layoutManager.getSelectedLayouts(subjectNa);
I get the error list
org.apache.jasper.JasperException: An exception occurred processing JSP page /search.jsp at line 72
Iterable<Layouts> waters = layoutManager.getSelectedLayouts(subjectNa);
java.lang.NullPointerException
com.amazon.basalt.examples.octane.tomcat.LayoutManager.getCurrentSession(LayoutManager.java:37)
com.amazon.basalt.examples.octane.tomcat.LayoutManager.getSelectedLayouts(LayoutManager.java:50)
org.apache.jasper.JasperException: java.lang.NullPointerException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:502)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:430)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
root cause
java.lang.NullPointerException com.amazon.basalt.examples.octane.tomcat.LayoutManager.getCurrentSession(LayoutManager.java:37)
com.amazon.basalt.examples.octane.tomcat.LayoutManager.getAllLayouts(LayoutManager.java:68)
org.apache.jsp.search_jsp._jspService(search_jsp.java:221)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
One possible solution. (If using scriplets is not an issue.)
<%
LayoutManager layoutManager = new LayoutManager();
String subjectName = request.getParameter("subjectName");
layoutManager.getSelectedLayouts(subjectName);
%>
Do remember to import the class in the JSP
I recommend you to use ajax to get the the list of layouts.