why am I receiving NullPointerException on my jsp file? - java

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

Related

Reading of project.properties file in jsp in hybris

I have a key in my project.properties as userKey=value
I wanna read the value in jsp with using configservice in java. Is there a possibility to do it?
I tried to use
<%# taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<spring:message code="label.username"/>
<spring:message code="label.password"/>
but it failed with below error :
WARN [hybrisHTTP30] [DefaultCMSComponentRendererRegistry] Error
processing component tag. currentComponent
[MerchGenericMediaComponentModel (8800615040060#15)] exception:
javax.serv
Sep 14, 2017 2:31:16 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
javax.servlet.jsp.JspTagException: No message found under code 'userKey' for locale 'en'.
at org.springframework.web.servlet.tags.MessageTag.doEndTag(MessageTag.java:200)
at org.apache.jsp.WEB_002dINF.views.mobile.cms.th.merchgenericmediacomponent_jsp._jspx_meth_spring_005fmessage_005f0(merchgenericmediacomponent_jsp.java:472)
at org.apache.jsp.WEB_002dINF.views.mobile.cms.th.merchgenericmediacomponent_jsp._jspService(merchgenericmediacomponent_jsp.java:130)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:747)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:603)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:542)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:160)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1257)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
This will work. Use the below snippet in the Jsp and replace the 'propertykey' with the one which you want to retrieve from local.properties or project.properties.
${jalosession.tenant.config.getParameter('propertykey')}
If you really only want to set some language properties than you should definitly use the:
\web\webroot\WEB-INF\messages\base.properties
for this configuration. Therefore this file was made. But if you have some other properties that you want to use in you *.jsp file you can use:
<spring:eval expression="T(de.hybris.platform.util.Config).getParameter('your.code')" var="myVar" scope="page" />
You should try putting your labels(in this case userKey=value) in base.properties file (or base_en.properties) instead of project.properties
base.properties is used for I18n, while
project.properties is used to configure ports, build environment, JVM options, etc...

Unable to compile the class for JSP

We are facing the below exception when I click on View button to see the user details :
2017-06-30 19:23:52,831 ERROR [com.myapp.jsp] - <Unable to compile class for JSP:
An error occurred at line: 53 in the jsp file: /WEB-INF/jsps/ViewUserDetails.jsp
apache cannot be resolved or is not a field
50: </myapphtml:myappRow>
51:
52: <myapphtml:myappRow align="left" label="userdetails.field.label.orgs">
53: <logic:iterate name="userDetails" property="Orgs" id="org">
54: <bean:write name="org" property="name" /><br>
55: </logic:iterate>
56: </myapphtml:myappRow>
Stacktrace:>
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 53 in the jsp file: /WEB-INF/jsps/ViewUserDetails.jsp
apache cannot be resolved or is not a field
50: </myapphtml:myappRow>
51:
52: <myapphtml:myappRow align="left" label="userdetails.field.label.orgs">
53: <logic:iterate name="userDetails" property="mappedOrgs" id="org">
54: <bean:write name="org" property="name" /><br>
55: </logic:iterate>
56: </myapphtml:myappRow>
Stacktrace:
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366)
at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:490)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:379)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:341)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:662)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:364)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
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:743)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:485)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:410)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:337)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1063)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:263)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:386)
at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:318)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:229)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
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 at com.myapp.tools.auth.client.AuthFilter.doFilter(AuthFilter.java:512)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at com.myapp.tools.auth.client.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:90)
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:218)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
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)
This happens only in the combination of RHEL 7.x and Tomcat combination.
I am not able to reproduce this issue in combination other then this.
Attaching the ViewUserDetails.jsp
<%# page import="org.apache.struts.Globals" %>
<%# page import="com.myapp.tools.api.impl.User" %>
<%# include file="include/commonDef.jspf" %>
<tiles:insert definition="myapp.csd.office.layout.default">
<tiles:put name="header" type="String">
<myapphtml:myappPageHeaderTab headerImage="images/default/icn_user.gif" headerText="form.page.title.user_details"/>
</tiles:put>
<tiles:put name="content" type="String">
<myapphtml:myappBlock>
<myapphtml:myappMessage
genErrorKey="<%= myappGlobals.GENERAL_ERROR %>"
valErrorKey="<%= Globals.ERROR_KEY %>"
genErrorHeading="MC.General.genError"
valErrorHeading="MC.General.genError"
headingBundle="myappBASETAG"/>
</myapphtml:myappBlock>
<strutshtml:form action="/processUserList.do" method="POST">
<input type="hidden" name="action" value="" />
<myapphtml:myappRow align="left" label="userdetails.field.label.orgs">
<logic:iterate name="userDetails" property="Orgs" id="org">
<bean:write name="org" property="name" /><br>
</logic:iterate>
</myapphtml:myappRow>
<myapphtml:myappButtonRow formname="UserDetailsForm">
<myapphtml:myappButton action="cancel" name="form.button.label.cancel" buttonStyle="button_gt" />
</myapphtml:myappButtonRow>
</strutshtml:form>
</tiles:put>
</tiles:insert>
Try to see if you have a String called org change it to other name as org1.
See answer.
String org = ""; something like this in jsp somewhere on the top of
that package statement. Change that variable name to org1 or some
other meaningful one and your problem will be solved.
There's a known issue in Tomcat which its Compiler is interpreting this as a reference to the field apache of object org
The code works in TC4 because the generated code is much simpler - it
ignores a number of possible error conditions. The fix for these
issues in TC5 and TC6 includes a fully qualified reference to
org.apache.jasper.runtime.JspRuntimeLibrary.URLEncode()
The complier is interpreting this as a reference to the field apache
of object org.
When you have generated code, there is always going to be the
possibility of a naming clash. I can't see an easy way around this.
I am going to mark this as WONTFIX. More generally, avoiding the use
of widely used package prefixes (org, com, etc) as variable names will
reduce your risk of hitting this issue.
As an aside, a quick Google suggests you might also want to avoid 2
letter variable names that clash with top level domains.
Notice that RHEL uses a specific tomcat version which not as community version.
Any community releases of Tomcat are not supported
The supported releases of Tomcat are included in our products:
Tomcat rpm package included in RHEL 7.1, which is based on Tomcat
7.0.54.
Please note that we backport critical bug and security fixes on the
above versions when issues are raised or CVEs are reported. Therefore,
the versions we provide are not exactly the same as community versions
of Tomcat.

Unterminated <html:form tag JSP

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.

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.

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