Unterminated <html:form tag JSP - java

I have a small problem . When i use form without if condition like
<html:form action="/customerDepositReport.doo?showCustDepsForPrintingReceipt_action=showCustDepsForPrintingReceipt">
it works fine but when i enclosed it in my if else like
<% if(session.getAttribute("correctionEntry")!=null) { %>
<html:form action="/preEntryCorrection.doo?entryCorrection_action=entryCorrection">
<input type="hidden" name="showDepositsList" value="">
<% }else{ %>
<html:form action="/customerDepositReport.doo?showCustDepsForPrintingReceipt_action=showCustDepsForPrintingReceipt">
<% } %>
It gives me an exception :
org.apache.jasper.JasperException: /jsp/custmngmt/reports/viewCustomerDepositReportCriteriaForOldReceipt.jsp(356,0) Unterminated <html:form tag
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:132)
org.apache.jasper.compiler.Parser.parseBody(Parser.java:1646)
org.apache.jasper.compiler.Parser.parseOptionalBody(Parser.java:976)
org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1247)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1421)
org.apache.jasper.compiler.Parser.parse(Parser.java:130)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:255)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:103)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:194)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:360)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:607)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:312)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
org.apache.struts.action.ActionServlet.processActionForward(ActionServlet.java:1833)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1670)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:514)
javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
I have tested the condition , it does enter the if part but causes exception when going through the form tag . I don't get it. Some help please.

please, terminate tags porperly,
</html:form> into your jsp file after <html:form> uses.
Your Error clearly says , Unterminated (see it)
means, you need to close every tag(here <html:form>) after it's uses.

Related

Dynamically created form with different number of inputs

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}__]}"

why am I receiving NullPointerException on my jsp file?

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}">

uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application

JSP, SQL experts, I'm so grateful that I have got working solutions to all my previous posts as I'm a newbie to the above programming languages with just basic college knowledge. After getting the Java - SQL database data extraction working via command line (for basic understanding of JDBC) I have shifted back to 'JSP - SQL database access'.
This is my first example but when i try to execute it I get a XML error message, that I guess is about Role Based Authentication, though I'm not sure. Please I request your assistance preferably with basic steps of the solution.
Below is the error message.
HTTP Status 500 - The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
type Exception report
message The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:56)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:445)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:117)
org.apache.jasper.compiler.TagLibraryInfoImpl.generateTLDLocation(TagLibraryInfoImpl.java:311)
org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:152)
org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:410)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:475)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1427)
org.apache.jasper.compiler.Parser.parse(Parser.java:138)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:242)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.47 logs.
Apache Tomcat/7.0.47
Here is the JSP code:
<%# page import="java.io.*, java.util.*, java.sql.*" %>
<%# page import="javax.servlet.http.*, javax.servlet.*" %>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<html>
<head>
<title>SELECT operation</title>
</head>
<body>
<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/EMP"
user="root" password="password"/>
<sql:query dataSource="${snapshot}" var="result">
SELECT * from Employees;
</sql:query>
<table border="1" width="100%">
<tr>
<th>Emp ID</th>
<th>Age</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
<td><c:out value="${row.id}"/></td>
<td><c:out value="${row.age}"/></td>
<td><c:out value="${row.first}"/></td>
<td><c:out value="${row.last}"/></td>
</tr>
</c:forEach>
</table>
</body>
</html>
Here are the file and class paths:
JSP page: C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\jsp pages\RegName.jsp
CLASSPATH: C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\jsp-api.jar;C:\glassfish3\jdk\jre\lib;C:\Program Files (x86)\MySQL\MySQL Connector J\mysql-connector-java-5.1.27-bin.jar
JAVA_HOME: C:\glassfish3\jdk
Path: C:\glassfish3\jdk\bin;C:\Program Files (x86)\MySQL\MySQL Server 5.0\bin
Late answer, but it can help other!
As stated here, you can add to your pom.xml:
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
It worked for me!
You need to add the jstl library to your classpath. Typically, it would go into WEB-INF/lib. You can get the binary jar here.

Pagination with Spring Hibernate

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.

Call java method in JSP file

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((La‌​youts)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.

Categories