This is the code I have put up in my jsp page just to test if it works or not correctly.
The jsp page works fine without any use of opencv classes.
But I got this error while using objects of the opencv library.
<%# page import="org.opencv.core.*" %>
<%# page import="org.opencv.highgui.Highgui" %>
<!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>Title</title>
</head>
<body>
<%
System.loadLibrary("opencv_java248");
Mat img = Highgui.imread("F:/project/im2.jpg");
%>
</body>
</html>
Attaching the error page for the details:
The error code is :
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:553)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:442)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
javax.servlet.ServletException: java.lang.UnsatisfiedLinkError: org.opencv.highgui.Highgui.imread_1(Ljava/lang/String;)J
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:911)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:840)
org.apache.jsp.first_jsp._jspService(first_jsp.java:79)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
java.lang.UnsatisfiedLinkError: org.opencv.highgui.Highgui.imread_1(Ljava/lang/String;)J
org.opencv.highgui.Highgui.imread_1(Native Method)
org.opencv.highgui.Highgui.imread(Highgui.java:359)
org.apache.jsp.first_jsp._jspService(first_jsp.java:68)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
The unsatisfied link error is telling you, that there was no library with such a name found.
See here: OpenCV + Java = UnsatisfiedLinkError.
On a side note, you really shouldn't be using code inside JSPs. Create a Servlet that does what you want with the image, add it's path/URL as an attribute request.setAttribute("key", "value").
Use a RequestDispatcher:
getServletContext().getRequestDispatcher("/path/to/page.jsp").forward(request, response)
to forward the request and response to the JSP. You can then reference it there with ${key}.
Related
<%# 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">
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:out value="${'Welcome to SevenMentor'}"/>
Output:
HTTP Status 500 – Internal Server Error
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 unexpected condition that prevented it from fulfilling the 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:55)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:293)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:80)
org.apache.jasper.compiler.TagLibraryInfoImpl.generateTldResourcePath(TagLibraryInfoImpl.java:251)
org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:122)
org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:434)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:492)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1448)
org.apache.jasper.compiler.Parser.parse(Parser.java:145)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:244)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:105)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:201)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:372)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:333)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:600)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:368)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
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.14
Your error basically says that necessary jar files are missing.
If it's a maven project then please add the dependencies.
If it's a normal project. please download and add the jar files in the eclipse
web directory.
Seeing the error, i guess you need jsp libraries and jstl libraries.
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)
I am trying to connect to Impala and run a query from my web application. Here is my jsp code:
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%# page import="java.sql.SQLException" %>
<%# page import="java.sql.Connection" %>
<%# page import="java.sql.ResultSet" %>
<%# page import="java.sql.Statement" %>
<%# page import="java.sql.DriverManager" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<%
Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver");
Connection con = DriverManager.getConnection("jdbc:hive2://localhost:21050/;auth=noSasl");
Statement stmt = con.createStatement();
String sql = "select * from logdata limit 10";
System.out.println("Running: " + sql);
ResultSet res = stmt.executeQuery(sql);
while (res.next()) {
System.out.println(String.valueOf(res.getInt(1)) + "\t" + res.getString(2));
}
%>
</body>
</html>
Here is the error that I get in my browser:
exception
org.apache.jasper.JasperException: javax.servlet.ServletException: java.sql.SQLException: Invalid URL: jdbc:hive2://localhost:21050/;auth=noSasl
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
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:722)
root cause
javax.servlet.ServletException: java.sql.SQLException: Invalid URL: jdbc:hive2://localhost:21050/;auth=noSasl
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:911)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:840)
org.apache.jsp.web.index_jsp._jspService(index_jsp.java:114)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
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:722)
root cause
java.sql.SQLException: Invalid URL: jdbc:hive2://localhost:21050/;auth=noSasl
org.apache.hadoop.hive.jdbc.HiveConnection.<init>(HiveConnection.java:86)
org.apache.hadoop.hive.jdbc.HiveDriver.connect(HiveDriver.java:106)
java.sql.DriverManager.getConnection(DriverManager.java:615)
java.sql.DriverManager.getConnection(DriverManager.java:213)
org.apache.jsp.web.index_jsp._jspService(index_jsp.java:91)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
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:722)
I am using CDH4 and Tomcat7. I've been wrestling with it for half a day now. What am I missing?
The problem is solved. Instead of:
Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver");
I should have used:
Class.forName("org.apache.hive.jdbc.HiveDriver");
Its very clear from this line ,
org.apache.jasper.JasperException: javax.servlet.ServletException:
java.sql.SQLException:
Invalid URL: jdbc:hive2://localhost:21050/;auth=noSasl
this line "jdbc:hive2://localhost:21050/;auth=noSasl" is invalid . so check for the coorect url to connect your jdbc driver .
Hope this helps!!
This is my JSP page. On button click, I am calling this JSP page which will convert the HTML document to a PDF document.
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import="java.io.*,com.itextpdf.text.*,com.itextpdf.tool.xml.*,com.itextpdf.text.pdf.PdfWriter"%>
<!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>
<%
//step 1
Document document = new Document();
// step 2
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("pdf.pdf"));
// step 3
document.open();
// step 4
XMLWorkerHelper.getInstance().parseXHtml(writer, document,new FileInputStream("C:/Documents and Settings/preetish/Desktop/practice/Buttons.html"));
//step 5
document.close();
%>
</body>
</html>
But when I am running index.jsp on an Apache Tomcat Server, it is giving me the following error log:
SEVERE: Servlet.service() for servlet [jsp] in context with path [/paginanation] threw exception [An exception occurred processing JSP page /pfd.jsp at line 19
16: // step 3
17: document.open();
18: // step 4
19: XMLWorkerHelper.getInstance().parseXHtml(writer, document,new FileInputStream("C:/Documents and Settings/preetish/Desktop/practice/Buttons.html"));
20: //step 5
21: document.close();
22:
Stacktrace:] with root cause
java.lang.ClassCastException: Insertion of illegal Element: 30
at com.itextpdf.text.Phrase.add(Phrase.java:367)
at com.itextpdf.text.Paragraph.add(Paragraph.java:345)
at com.itextpdf.tool.xml.html.Div.end(Div.java:117)
at com.itextpdf.tool.xml.html.AbstractTagProcessor.endElement(AbstractTagProcessor.java:189)
at com.itextpdf.tool.xml.pipeline.html.HtmlPipeline.close(HtmlPipeline.java:206)
at com.itextpdf.tool.xml.XMLWorker.endElement(XMLWorker.java:141)
at com.itextpdf.tool.xml.parser.XMLParser.endElement(XMLParser.java:395)
at com.itextpdf.tool.xml.parser.state.ClosingTagState.process(ClosingTagState.java:70)
at com.itextpdf.tool.xml.parser.XMLParser.parseWithReader(XMLParser.java:235)
at com.itextpdf.tool.xml.parser.XMLParser.parse(XMLParser.java:213)
at com.itextpdf.tool.xml.parser.XMLParser.parse(XMLParser.java:174)
at com.itextpdf.tool.xml.XMLWorkerHelper.parseXHtml(XMLWorkerHelper.java:223)
at com.itextpdf.tool.xml.XMLWorkerHelper.parseXHtml(XMLWorkerHelper.java:185)
at org.apache.jsp.pfd_jsp._jspService(pfd_jsp.java:76)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
You have forgotten to import Document class.
<% page import="class">
This is the way to import in jsp page
You yourself are using loose HTML4 (in the JSP at least), and are trying to convert XHTML.
In general: make a standalone application (library) to have an easier development.
Turn the original HTML4 page into XHTML, and validate the page (Tiny Validator, any browser plugin.)
The error aludes probably an illegal element, like
<b><p>lorem</p><p>ipsum</p></b>
A p-tag is not allowed inside a b-tag.
As you know XHTML needs singletons to be written as <img .../>. For HTML you could leave a space before />. An open tag <p> needs a clöosing tag </p>.
I am having Jsp file under root folder in Tomcat and i want to include another jsp file which is placed under webapps folder. while i am trying following code
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<jsp:include page="../docs/index.html"/>
</body>
</html>
i am getting the following exception
HTTP Status 500 - An exception occurred processing JSP page /trail.jsp at line 16
type Exception report
message An exception occurred processing JSP page /trail.jsp at line 16
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /trail.jsp at line 16
13: </head>
14: <body>
15: <h1>Hello World!</h1>
16: <jsp:include page="../docs/index.html"/>
17: </body>
18: </html>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
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)
root cause
java.lang.NullPointerException
org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
org.apache.jsp.trail_jsp._jspService(trail_jsp.java:73)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
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.42 logs.
Please help me to include the jsp under webapps folder in tomcat.
Thanks in advance
the file in webapps/doc/ will not be in the same context as trail.jsp. You can not include a jsp from another context. Although according to the code you are trying to include a static file. If this is right please update your description.
Try from the directory WEB-INF/views (src/main/webapp/WEB-INF/views)
<jsp:include page="/WEB-INF/views/index.jsp" />