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}__]}"
Related
I have tried to make a simple custom tag JSP application, bu talternatively I keep receiving this error, or sometimes Unable to load tag handler class "HelloTag" for tag "ex:Hello".
My index.jsp looks like this:
<%#page contentType="text/html;charset=UTF-8" language="java" %>
<%#taglib prefix="ex" uri="WEB-INF/custom.tld"%>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>customised tag</title>
</head>
<body>
<ex:Hello/>
</body>
</html>
My custom.tld from WEB-INF looks like this:
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>2.0</jsp-version>
<short-name>Example TLD</short-name>
<tag>
<name>Hello</name>
<tag-class>HelloTag</tag-class>
<body-content>empty</body-content>
</tag>
</taglib>
And this is the Java class HelloTag.java from WEB-INF/classes:
import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;
import java.io.*;
public class HelloTag extends SimpleTagSupport {
public void doTag() throws JspException, IOException {
JspWriter out = getJspContext().getOut();
out.write("Hello Custom Tag!");
}
}
The entire error log:
exception
org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.labJavaIJ.web.index_jsp
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:177)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:376)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.ClassNotFoundException: org.apache.jsp.labJavaIJ.web.index_jsp
java.net.URLClassLoader.findClass(URLClassLoader.java:381)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:132)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:172)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:376)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
This question already has answers here:
java.lang.IllegalStateException: Cannot (forward | sendRedirect | create session) after response has been committed
(9 answers)
Closed 6 years ago.
I create one JSP form and when i click on submit button my below doPost method call and this redirect to another jsp Error page with attribute "errorMessage"
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
request.setAttribute("errorMessage", "You are not authorized to access the Hub System.");
RequestDispatcher view = request.getRequestDispatcher("/error.jsp");
view.forward(request, response);
}
} catch (ServletException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
My Error jsp page
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<table align="center">
<tr align="center">
<td><img src="images/logo.jpg" /></td>
</tr>
<tr>
<td>
<p style="color: red;">${errorMessage}</p>
</td>
</tr>
</table>
</body>
</html>
This scenario work perfectly but on my tomcat log i am getting below Error.
java.lang.IllegalStateException: Cannot forward after response has been committed
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:328)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318)
at otn.aitc.io.MainServlet.doPost(MainServlet.java:203)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1502)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1458)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
I am using Java with Tomcat 8.
Tomcat maintains an internal buffer where it stores (part of) the response. The most important part is the status code and the headers. If an error occurs it can discard that buffer and send an error page for instance.The same happens if you try to send a redirect.
All these is possible because that buffer can be discarded. But if it has been sendt to the client, then there is nothing to be done, the client would have already received the response code and the headers, and the redirect is performed exactly by headers (Location) and a status code (301 or 302).
So the solution to your problem is not to commit the response - e.g, calling flush() on the response output stream, not filling up that buffer thus forcing tomcat to flush it, or even better do not try to send anything to the client if you intend to make a redirect.
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.
I have a problem with calling Java method from .jsp file. I converted my project into Maven but still have the same problem.
My .jsp file is in /db-reagencii/WebContent/reagents/reagents.jsp
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%#page import="cz.dbReagents.web.reagentsWeb.ReagentsWeb"%>
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Reagencie</title>
</head>
<body>
<jsp:include page="../WEB-INF/menu/menu.jsp"/>
Reagents
<jsp:useBean id="podnikyWeb" class="cz.dbReagents.web.reagentsWeb.ReagentsWeb" scope="request"/>
</body>
</html>
and i want call method from this class
package cz.dbReagents.web.reagentsWeb;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import cz.dbReagents.dto.reagents.Reagents;
public class ReagentsWeb implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
public Collection<Reagents> getReagents(){
ArrayList<Reagents> result = new ArrayList<Reagents>();
result.add(new Reagents("testovaci reagencie",11));
System.out.print(result.get(0).getName());
return result;
}
}
and this class
package cz.dbReagents.dto.reagents;
import java.io.Serializable;
public class Reagents implements Serializable{
private static final long serialVersionUID = 1L;
private String name;
private int sum;
public Reagents(){
}
public Reagents(String name, int sum){
this.name = name;
this.sum = sum;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSum() {
return sum;
}
public void setSum(int sum) {
this.sum = sum;
}
}
but when I tried to load page a got this error
VI 11, 2015 8:47:28 ODP. org.apache.catalina.core.StandardWrapperValve
invoke SEVERE: Servlet.service() for servlet [jsp] in context with
path [/db-reagencii] threw exception [/reagents/reagents.jsp (line:
17, column: 1) The value for the useBean class attribute
cz.dbReagents.web.reagentsWeb.ReagentsWeb is invalid.] with root cause
org.apache.jasper.JasperException: /reagents/reagents.jsp (line: 17,
column: 1) The value for the useBean class attribute
cz.dbReagents.web.reagentsWeb.ReagentsWeb is invalid. at
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
at
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:443)
at
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:149)
at
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1242)
at org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1196) at
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2392) at
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2444) at
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2450) at
org.apache.jasper.compiler.Node$Root.accept(Node.java:474) at
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2392) at
org.apache.jasper.compiler.Generator.generate(Generator.java:3529) at
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:251)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:374) 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.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
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)
Is there a chance that I have bad configured server?
I have web.xml in /db-reagencii/WebContent/WEB-INF/web.xml and contains this:
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Databáze Reagencií</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
I am using Tomcat 7.0.
This is my first web application in Java so I am sure that there is some stupid mistake but I can't find it.
Thanks for any advice :)
My error with scriplet.
VI 11, 2015 11:09:00 ODP.
org.apache.catalina.core.StandardWrapperValve invoke SEVERE:
Servlet.service() for servlet [jsp] in context with path
[/db-reagencii] threw exception [Unable to compile class for JSP:
An error occurred at line: [14] in the generated java file:
[/home/michal/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/db-reagencii/org/apache/jsp/reagents/reagents_jsp.java]
Only a type can be imported.
cz.dbReagents.web.reagentsWeb.ReagentsWebHandler resolves to a package
An error occurred at line: [15] in the generated java file:
[/home/michal/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/db-reagencii/org/apache/jsp/reagents/reagents_jsp.java]
Only a type can be imported. cz.dbReagents.dto.reagents.Reagents
resolves to a package
An error occurred at line: 18 in the jsp file: /reagents/reagents.jsp
ReagentsWebHandler cannot be resolved to a type 15: 16: Reagents 17: 18: <%
ReagentsWebHandler r = new ReagentsWebHandler(); %> 19: 20:
21:
An error occurred at line: 18 in the jsp file: /reagents/reagents.jsp
ReagentsWebHandler cannot be resolved to a type 15: 16: Reagents 17: 18: <%
ReagentsWebHandler r = new ReagentsWebHandler(); %> 19: 20:
21:
Stacktrace:] with root cause org.apache.jasper.JasperException: Unable
to compile class for JSP:
An error occurred at line: [14] in the generated java file:
[/home/michal/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/db-reagencii/org/apache/jsp/reagents/reagents_jsp.java]
Only a type can be imported.
cz.dbReagents.web.reagentsWeb.ReagentsWebHandler resolves to a package
An error occurred at line: [15] in the generated java file:
[/home/michal/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/db-reagencii/org/apache/jsp/reagents/reagents_jsp.java]
Only a type can be imported. cz.dbReagents.dto.reagents.Reagents
resolves to a package
An error occurred at line: 18 in the jsp file: /reagents/reagents.jsp
ReagentsWebHandler cannot be resolved to a type 15: 16: Reagents 17: 18: <%
ReagentsWebHandler r = new ReagentsWebHandler(); %> 19: 20:
21:
An error occurred at line: 18 in the jsp file: /reagents/reagents.jsp
ReagentsWebHandler cannot be resolved to a type 15: 16: Reagents 17: 18: <%
ReagentsWebHandler r = new ReagentsWebHandler(); %> 19: 20:
21:
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:485)
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.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
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)
I got this error when I put only this lines into ragents.jsp
<%# page import="cz.dbReagents.web.reagentsWeb.ReagentsWebHandler " %> <h1>Hello World</h1>
VI 11, 2015 11:14:05 ODP.
org.apache.catalina.core.StandardWrapperValve invoke SEVERE:
Servlet.service() for servlet [jsp] in context with path
[/db-reagencii] threw exception [Unable to compile class for JSP:
An error occurred at line: [14] in the generated java file:
[/home/michal/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/db-reagencii/org/apache/jsp/reagents/reagents_jsp.java]
Only a type can be imported.
cz.dbReagents.web.reagentsWeb.ReagentsWebHandler resolves to a package
Stacktrace:] with root cause org.apache.jasper.JasperException: Unable
to compile class for JSP:
An error occurred at line: [14] in the generated java file:
[/home/michal/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/db-reagencii/org/apache/jsp/reagents/reagents_jsp.java]
Only a type can be imported.
cz.dbReagents.web.reagentsWeb.ReagentsWebHandler resolves to a package
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:485)
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.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
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)
When I deploy war files into tomcat i got this error
VI 11, 2015 11:50:18 ODP. org.apache.catalina.core.ApplicationContext
log INFO: ContextListener: contextInitialized() VI 11, 2015 11:50:18
ODP. org.apache.catalina.core.ApplicationContext log INFO:
SessionListener: contextInitialized() VI 11, 2015 11:50:18 ODP.
org.apache.catalina.core.ApplicationContext log INFO: ContextListener:
attributeAdded('org.apache.jasper.compiler.TldLocationsCache',
'org.apache.jasper.compiler.TldLocationsCache#68ccc170') VI 11, 2015
11:50:45 ODP. org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path
[/db-reagencii] threw exception [Unable to compile class for JSP:
An error occurred at line: [14] in the generated java file:
[/home/michal/apps/apache-tomcat-7.0.62/work/Catalina/localhost/db-reagencii/org/apache/jsp/reagents/reagents_jsp.java]
Only a type can be imported.
cz.dbReagents.web.reagentsWeb.ReagentsWebHandler resolves to a package
Stacktrace:] with root cause org.apache.jasper.JasperException: Unable
to compile class for JSP:
An error occurred at line: [14] in the generated java file:
[/home/michal/apps/apache-tomcat-7.0.62/work/Catalina/localhost/db-reagencii/org/apache/jsp/reagents/reagents_jsp.java]
Only a type can be imported.
cz.dbReagents.web.reagentsWeb.ReagentsWebHandler resolves to a package
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:485)
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.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
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)
you have an extra space before "page" in the JSP Import directive:
<%#page import="cz.dbReagents.web.reagentsWeb.ReagentsWeb"%>
It should be:
<%# page import="cz.dbReagents.web.reagentsWeb.ReagentsWeb"%>
I really hate using java sentences in JSP but if you want to do it this way, just modify your ReagentsWeb this way:
public class ReagentsWeb {
public Collection<Reagents> reagents;
public ReagentsWeb(){
reagents = this.getReagents();
}
public Collection<Reagents> getReagents(){
ArrayList<Reagents> result = new ArrayList<Reagents>();
result.add(new Reagents("testovaci reagencie",11));
return result;
}
}
In your JSP do this:
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%#page import="cz.dbReagents.web.reagentsWeb.ReagentsWeb"%>
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Reagencie</title>
</head>
<body>
<jsp:include page="../WEB-INF/menu/menu.jsp"/>
Reagents
<%
for(Reagent r : reagents){
out.println(r.getName());
}
%>
</body>
</html>
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.