So I am trying to call a Java method in LoginCheckAction.java from LoginCheckAction.jsp. The method in the prior calls a method in LoginCheckBO.java which is an interface implemented by LoginCheckBOImpl. I am getting an error.
LoginCheckAction.jsp
<%# page import="action.LoginCheckAction" %>
<%# page import="bo.LoginCheckBO" %>
<%# page import="bo.impl.LoginCheckBOImpl" %>
<%
String username = request.getParameter("username");
String password = request.getParameter("password");
LoginCheckAction ls = new LoginCheckAction();
// ls.printSomething(username);
ls.startBo(username);
%>
LoginCheckAction.java
package action;
import bo.LoginCheckBO;
import bo.impl.LoginCheckBOImpl;
public class LoginCheckAction{
LoginCheckBO bo = new LoginCheckBOImpl();
public LoginCheckAction(){
super();
}
public void printSomething(String username){
System.out.println(username);
}
public void startBo(String username){
bo.printSomethingBO(username);
}
}
LoginCheckBO.java
package bo;
public interface LoginCheckBO{
public void printSomethingBO(String username);
}
LoginCheckBOImpl.java
package bo.impl;
import bo.LoginCheckBO;
public class LoginCheckBOImpl implements LoginCheckBO{
public void printSomethingBO(String username){
System.out.println(username);
}
}
The error is in LoginCheckAction.jsp and I don't understand why I am getting that error. Can someone please explain? Here is the error:
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 /jsp/LoginCheckAction.jsp at line 10
7:
8: LoginCheckAction ls = new LoginCheckAction();
9: // ls.printSomething(username);
10: ls.startBo(username);
11: %>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.lang.NullPointerException
action.LoginCheckAction.startBo(LoginCheckAction.java:26)
org.apache.jsp.jsp.LoginCheckAction_jsp._jspService(LoginCheckAction_jsp.java:65)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
Related
I have this uni project going on, and I'm stuck on this error and can't find the solution.
First there's the JSP file that loads a list
<%#page import="Controllers.RestClient"%>
<%#page import="java.util.List"%>
<%#page import="Model.Stationss"%>
<%#page import="javax.xml.bind.JAXBException"%>
<%#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>
<label for="Origin">Embark Station:</label>
<select name ="StartStation" id="stations">
<%
List<Stationss> listS = RestClient.getStations();
for (int i = 0; i < listS.size(); i++) {
out.print("<option value = " + i + ">" + listS.get(i).getName() + "</option>");
}
%>
</select><br>
</body>
</html>
There's also the ReST client access
package Controllers;
import java.util.List;
import Model.Stationss;
import java.util.ArrayList;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.xml.bind.JAXBException;
public class RestClient {
public static List<Stationss> getStations() {
System.out.print("test");
String link = "http://localhost:8080";
String path = "/Service/webresources/pkg.service.stations";
Client client = ClientBuilder.newBuilder().build();
WebTarget target = client.target(link).path(path);
Invocation.Builder invocation = target.request(MediaType.APPLICATION_XML);
System.out.print(link);
System.out.print(path);
Response response = invocation.get(Response.class);
System.out.print(response);
List<Stationss> list = response.readEntity(new GenericType<List<Stationss>>() {
});
System.out.print(list);
return list;
}
};
and after I have the model
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package Model;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement
public class Stationss {
private int id;
private String name;
private int zone;
Gate gates = new Gate(zone);
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getZone() {
return zone;
}
public void setZone(int zone) {
this.zone = zone;
}
public Gate getGates() {
return gates;
}
public void setGates(Gate gates) {
this.gates = gates;
}
public Stationss() {
}
public Stationss(int id, String name, int zone) {
this.id = id;
this.name = name;
this.zone = zone;
}
#Transient
public CheckTicket enter(String xml) {
return gates.enter(xml);
}
#Transient
public boolean exit(String xml) {
return gates.exit(xml);
}
}
and at last, the huge error screen
HTTP Status 500 – Internal Server Error
Type Exception Report
Message An exception occurred processing [/newjsp.jsp] at line [23]
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
org.apache.jasper.JasperException: An exception occurred processing [/newjsp.jsp] at line [23]
20: <label for="Origin">Embark Station:</label>
21: <select name ="StartStation" id="stations">
22: <%
23: List<Stationss> listS = RestClient.getStations();
24: for (int i = 0; i < listS.size(); i++) {
25: out.print("<option value = " + i + ">" + listS.get(i).getName() + "</option>");
26: }
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:610)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:499)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:380)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:328)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
javax.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error
org.glassfish.jersey.jaxb.internal.AbstractCollectionJaxbProvider.readFrom(AbstractCollectionJaxbProvider.java:359)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.invokeReadFrom(ReaderInterceptorExecutor.java:257)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:236)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:156)
org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1091)
org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:874)
org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:834)
org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:363)
org.glassfish.jersey.client.InboundJaxrsResponse$2.call(InboundJaxrsResponse.java:126)
org.glassfish.jersey.internal.Errors.process(Errors.java:316)
org.glassfish.jersey.internal.Errors.process(Errors.java:298)
org.glassfish.jersey.internal.Errors.process(Errors.java:229)
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:389)
org.glassfish.jersey.client.InboundJaxrsResponse.runInScopeIfPossible(InboundJaxrsResponse.java:264)
org.glassfish.jersey.client.InboundJaxrsResponse.readEntity(InboundJaxrsResponse.java:123)
Controllers.RestClient.getStations(RestClient.java:36)
org.apache.jsp.newjsp_jsp._jspService(newjsp_jsp.java:143)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:380)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:328)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory]
javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:269)
javax.xml.bind.ContextFinder.find(ContextFinder.java:412)
javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:721)
javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662)
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getStoredJaxbContext(AbstractJaxbProvider.java:288)
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getJAXBContext(AbstractJaxbProvider.java:273)
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getUnmarshaller(AbstractJaxbProvider.java:189)
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getUnmarshaller(AbstractJaxbProvider.java:164)
org.glassfish.jersey.jaxb.internal.AbstractCollectionJaxbProvider.readFrom(AbstractCollectionJaxbProvider.java:289)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.invokeReadFrom(ReaderInterceptorExecutor.java:257)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:236)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:156)
org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1091)
org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:874)
org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:834)
org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:363)
org.glassfish.jersey.client.InboundJaxrsResponse$2.call(InboundJaxrsResponse.java:126)
org.glassfish.jersey.internal.Errors.process(Errors.java:316)
org.glassfish.jersey.internal.Errors.process(Errors.java:298)
org.glassfish.jersey.internal.Errors.process(Errors.java:229)
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:389)
org.glassfish.jersey.client.InboundJaxrsResponse.runInScopeIfPossible(InboundJaxrsResponse.java:264)
org.glassfish.jersey.client.InboundJaxrsResponse.readEntity(InboundJaxrsResponse.java:123)
Controllers.RestClient.getStations(RestClient.java:36)
org.apache.jsp.newjsp_jsp._jspService(newjsp_jsp.java:143)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:380)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:328)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1444)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1252)
javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:122)
javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:155)
javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:267)
javax.xml.bind.ContextFinder.find(ContextFinder.java:412)
javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:721)
javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662)
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getStoredJaxbContext(AbstractJaxbProvider.java:288)
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getJAXBContext(AbstractJaxbProvider.java:273)
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getUnmarshaller(AbstractJaxbProvider.java:189)
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getUnmarshaller(AbstractJaxbProvider.java:164)
org.glassfish.jersey.jaxb.internal.AbstractCollectionJaxbProvider.readFrom(AbstractCollectionJaxbProvider.java:289)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.invokeReadFrom(ReaderInterceptorExecutor.java:257)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:236)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:156)
org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1091)
org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:874)
org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:834)
org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:363)
org.glassfish.jersey.client.InboundJaxrsResponse$2.call(InboundJaxrsResponse.java:126)
org.glassfish.jersey.internal.Errors.process(Errors.java:316)
org.glassfish.jersey.internal.Errors.process(Errors.java:298)
org.glassfish.jersey.internal.Errors.process(Errors.java:229)
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:389)
org.glassfish.jersey.client.InboundJaxrsResponse.runInScopeIfPossible(InboundJaxrsResponse.java:264)
org.glassfish.jersey.client.InboundJaxrsResponse.readEntity(InboundJaxrsResponse.java:123)
Controllers.RestClient.getStations(RestClient.java:36)
org.apache.jsp.newjsp_jsp._jspService(newjsp_jsp.java:143)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:380)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:328)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Note The full stack trace of the root cause is available in the server logs.
Apache Tomcat/10.0.16
It's my first time learning java and I'm completely at loss on what I'm doing wrong.
I know the link the xml list is working fine.
You have missing dependencies on your classpath
See the stack trace
javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
This answer might be helpful
I'm using the latest TomCat version and I've recently installed Eclipse IDE for Java Developers - 2021-03
This is my class:this is my class package
package com.DB;
import java.sql.Connection;
import java.sql.DriverManager;
public class DBConnect {
private static Connection conn;
public static Connection getConn()
{
try {
Class.forName("com.mysql.cj.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/ebook-app","root","password");
} catch (Exception e) {
e.printStackTrace();
}
return conn;
}
}
So this is my jsp code for class:
<%#page import="com.DB.DBConnect.* " %>
<% Connection conn=DBConnect.getConn();//My error in this line.why?
out.println(conn);
%>
I'm getting Error like this:
HTTP Status 500 – Internal Server Error
Type Exception Report
Message Unable to compile class for JSP:
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: [33] in the jsp file: [/index.jsp]
Connection cannot be resolved to a type
30: </div>
31:
32: <%#page import="com.DB.DBConnect.* " %>
33: <% Connection conn=DBConnect.getConn();
34: out.println(conn);
35: %>
36:
An error occurred at line: [33] in the jsp file: [/index.jsp]
DBConnect cannot be resolved
30: </div>
31:
32: <%#page import="com.DB.DBConnect.* " %>
33: <% Connection conn=DBConnect.getConn();
34: out.println(conn);
35: %>
36:
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:213)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:482)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:392)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:362)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:346)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:605)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:400)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:378)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:326)
javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Note The full stack trace of the root cause is available in the server logs.
Apache Tomcat/9.0.43
1st Error page
2nd Error page
Simply, What my problem is ,I'm getting the Error in jsp: line 33;
<% Connection conn=DBConnect.getConn(); //My error in this line.why?
I'm beginner for java,so please explain it in simple and clear way...
Your package com.DB has only one class i.e. DBConnect. You can import till com.DB.* and instead of getting connection object in jsp and printing here in jsp, return the string representation or string value of connection object from one method in your java class and then print it here.
I get the following Tomcat error when I run my JSP. I know what the error is I just don't why I'm getting it:
type Exception report
message org.apache.jasper.JasperException: java.lang.IllegalStateException: getOutputStream() has already been called for this response
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: org.apache.jasper.JasperException: java.lang.IllegalStateException: getOutputStream() has already been called for this response
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)
org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)
root cause
org.apache.jasper.JasperException: java.lang.IllegalStateException: getOutputStream() has already been called for this response
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:465)
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)
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:746)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:716)
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:868)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
org.apache.jsp.Ref.RefReportCntrl_jsp._jspService(RefReportCntrl_jsp.java:630)
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)
org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)
root cause
java.lang.IllegalStateException: getOutputStream() has already been called for this response
org.apache.catalina.connector.Response.getWriter(Response.java:640)
org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:214)
org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)
org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:190)
org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:126)
org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:80)
org.apache.jsp.Ref.refverify_005ferr_jsp._jspService(refverify_005ferr_jsp.java:124)
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)
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:746)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:716)
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:868)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
org.apache.jsp.Ref.RefReportCntrl_jsp._jspService(RefReportCntrl_jsp.java:630)
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)
org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)
At the top of the JSP I have these lines:
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%# page import="java.util.*,org.apache.log4j.Logger" %>
<%# page isErrorPage="false" errorPage="refverify_err.jsp" %>
<%# page trimDirectiveWhitespaces="true" %>
<%# page session="true" %>
<jsp:useBean id="da" class="reports.DemographicAge"/>
Later in the same JSP I call a method that eventually calls jasper-reports:
if(sectionA.equalsIgnoreCase("Demographics - Age")) {
result = da.convertDtosToXml(host, parameters, response, pathToweb);
}
The HttpServletResponse object “response” is passed to the following method where the error occurs during the call to JasperExportManager.exportReportToPdfStream():
package reports;
import dao.DemographicsAgeDao;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
public class DemographicAge {
private String generateDemographicAgeReport(ResultDataSource ds, Map parameters,
HttpServletResponse response, String host,
String path) throws RefugeeException {
String relativePath = path + "/Demographics_Age.xml";
String logo_path = path + "/logo.jpg";
File fin = new File(relativePath);
JasperReport jasperReport = null;
JasperDesign jasperDesign;
try {
jasperDesign = JRXmlLoader.load(fin);
jasperReport = JasperCompileManager.compileReport(jasperDesign);
} catch (JRException e) {
e.printStackTrace();
}
parameters.put("Report Title", "Health Assessment Report");
parameters.put("Sub Title", "Reported by " + (String) parameters.get("colname"));
parameters.put("logo", logo_path);
JasperPrint jasperPrint = null;
try {
//Fill the JasperPrint object with the report data
jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, ds);
//Create a unique filename using date/time
String date1 = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date());
String fileName = "attachment; filename=\"DemographicsAgeReport_" + date1 + ".pdf\"";
//Set the HTTP response header information
response.setHeader("Content-disposition", fileName);
response.setContentType("application/pdf");
try {
ServletOutputStream stream = response.getOutputStream();
JasperExportManager.exportReportToPdfStream(jasperPrint, stream);
stream.flush();
stream.close();
} catch (IOException e) {
throw new RefugeeException("IO Exception while writing the content into PDF.", e.getMessage());
}
} catch (JRException e) {
throw new RefugeeException("Jasper exception while filling the report", e.getMessage());
}
return "success";
}
}
I have reviewed the following Stack Overflow posts and still need some guidance on how to fix this:
Using PrintWriter and OutputStream
java.lang.IllegalStateException: getOutputStream() has already been called for this response when calling JasperReport
getOutputStream() has already been called for this response
The Tomcat error posted was a detractor. My code had a try/catch block for exceptions that included a call to a custom error jsp page (RefReportCntrl_jsp.java). When RefReportCntrl_jsp.java tried to push character data to the response stream, which was currently open as a bit stream, it caused a second error which is what was recorded in the error log.
The real error was discovered by looking at the exception string to be displayed by RefReportCntrl_jsp.java prior to the second exception being thrown.
The real error was that the project was using an older version of Jasper with a newer version of iText. When Jasper called a method in iText that no longer existied as that name it threw a method not found exception.
Can anyone please tell me to use which jdbc driver to connect with oracle 9.0.1.1?
i'm using jdk1.6.
i've used classes12 and ojdbc6 but they are causing errors.
Following is my code
Following bean's database related code is working in simple Java application but when i use it within JSF page it is giving Java null pointer exception error.
Thanks in advance.
Bean class:
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
#ManagedBean
#SessionScoped
public class Db implements Serializable{
int eId;
public int geteId() {
return eId;
}
public void seteId(int eId) {
this.eId = eId;
}
public static Connection getConnection() throws Exception {
String driver = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:#localhost:1521:globldb3";
String username = "scott";
String password = "tiger";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, username, password);
return conn;
}
public String addEmployee() throws Exception{
Connection conn = null;
PreparedStatement pstmt = null;
try {
int a = this.eId;
conn = getConnection();
String query = "INSERT INTO c(n) VALUES(?)";
pstmt = conn.prepareStatement(query);
pstmt.setInt(1,a);
pstmt.executeUpdate(); // execute insert statement
return "success";
} catch (Exception e) {
e.printStackTrace();
return "failure";
} finally {
pstmt.close();
conn.close();
}
}
}
Following is my JSF page
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<body>
<h:form>
<p>Enter value <h:inputText value="#{db.eId}"/> </p>
<p> <h:commandButton value="Add record" action="#{db.addEmployee}"/> </p>
</h:form>
</body>
</html>
Following exception is comeing while using ojdbc6.jar.
java.sql.SQLException: ORA-03120: two-task conversion routine: integer overflow
Following is stack trace of above exception
java.sql.SQLException: ORA-03120: two-task conversion routine: integer overflow
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:440)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:837)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:445)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:191)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:523)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1010)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1315)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3576)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3657)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1350)
at erpJavaFiles.Employee.addEmployee(Employee.java:113)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.el.parser.AstValue.invoke(AstValue.java:262)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:787)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1252)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
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:161)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:558)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:379)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:259)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:237)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:281)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
try ojdbc14.jar. it will work definetely.
You should not be using classes12.jar; that's for JDK 1.2. ojdbc6.jar is what you want; that's appropriate for JDK 6.
Check the value of a and the data type of column n in table c. Ensure column n has a set length, i.e. NUMBER(10,0) vs just NUMBER.
I would try the query in SQL Developer too. If you don't already have it you can get it here.
There's Oracle bug 5671074 in some 9i versions that causes this exception when server and client have different "endianness".
Are you sure it's not your case?
I need to display the newly generated excel (from tables using Apache POI) in a web browser (whatever it is, Firefox, Opera or IE). I've created the JSP file with
contentType="application/vnd.ms-excel"
But I'm not getting it.
Here's my code snippet :
<%#page session="true" contentType="application/vnd.ms-excel" pageEncoding="UTF-8"%>
<%#page import="org.apache.poi.ss.usermodel.CellStyle"%>
<%#page import="java.sql.DriverManager"%>
<%#page import="java.sql.ResultSet"%>
<%#page import="java.sql.Statement"%>
<%#page import="java.sql.Connection"%>
<%#page import="org.apache.poi.ss.usermodel.CreationHelper"%>
<%#page import="org.apache.poi.hssf.usermodel.HSSFCell"%>
<%#page import="org.apache.poi.hssf.usermodel.HSSFRow"%>
<%#page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%#page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
<html>
<head>
<%!
int r=0;
HSSFWorkbook book;
HSSFSheet sheet;
HSSFRow row;
CreationHelper createHelper = book.getCreationHelper();
Connection conn;
Statement stmt;
ResultSet rs;
%>
<title>Report</title>
<%
book = new HSSFWorkbook();
sheet = book.createSheet("Report");
%>
</head>
<body>
<%
try {
// Header of the Excel File
row = sheet.createRow(r);
row.createCell(0).setCellValue("Visit ID");
row.createCell(1).setCellValue("Carrier Name");
row.createCell(2).setCellValue("Phone Number");
row.createCell(3).setCellValue("Patient Name");
row.createCell(4).setCellValue("Subscriber ID");
row.createCell(5).setCellValue("Subscriber Name");
row.createCell(6).setCellValue("Chart Number");
row.createCell(7).setCellValue("Date Of Birth");
row.createCell(8).setCellValue("Subscriber Employer");
row.createCell(9).setCellValue("Service Date");
row.createCell(10).setCellValue("Provider Name");
row.createCell(11).setCellValue("CPT Code");
row.createCell(12).setCellValue("Aging Date");
row.createCell(13).setCellValue("Total");
row.createCell(14).setCellValue("Follow Up Notes");
row.createCell(15).setCellValue("Internal Status Code");
CellStyle cellStyle = book.createCellStyle();
cellStyle.setDataFormat(createHelper.createDataFormat().getFormat("MM/dd/yyyy"));
Statement stNotes;
ResultSet rsNotes;
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/maintain", "root", "root");
stmt = conn.createStatement();
stNotes = conn.createStatement();
rs = stmt.executeQuery("SELECT b.VisitID, b.CarrierName, b.PhoneNum, b.PatientName, "
+ "b.SubscriberID, b.SubscriberName, b.ChartNum, b.DoB, b.SubscriberEmp, "
+ "b.ServiceDate, b.ProviderName, b.CPTCode, b.BillingDate, b.BalanceAmt "
+ "FROM billing b INNER JOIN followup f ON b.VisitID = f.VisitID GROUP BY VisitID");
while(rs.next()) {
r++;
row = sheet.createRow(r);
row.createCell(0).setCellValue(rs.getString("VisitID"));
row.createCell(1).setCellValue(rs.getString("CarrierName"));
row.createCell(2).setCellValue(rs.getString("PhoneNum"));
row.createCell(3).setCellValue(rs.getString("PatientName"));
row.createCell(4).setCellValue(rs.getString("SubscriberID"));
row.createCell(5).setCellValue(rs.getString("SubscriberName"));
row.createCell(6).setCellValue(rs.getString("ChartNum"));
row.createCell(7).setCellValue(rs.getString("DoB"));
row.createCell(8).setCellValue(rs.getString("SubscriberEmp"));
row.createCell(9).setCellValue(rs.getString("ServiceDate"));
row.createCell(9).setCellStyle(cellStyle);
row.createCell(10).setCellValue(rs.getString("ProviderName"));
row.createCell(11).setCellValue(rs.getString("CPTCode"));
row.createCell(12).setCellValue(rs.getString("BillingDate"));
row.createCell(12).setCellStyle(cellStyle);
row.createCell(13).setCellValue(rs.getString("BalanceAmt"));
rsNotes = stNotes.executeQuery("SELECT Date, InternalStatusCode, FollowUpNote "
+ "FROM followup WHERE VisitID='" + rs.getString("VisitID") + "' ORDER BY Date");
while(rsNotes.next()) {
row.createCell(14).setCellValue(rsNotes.getString("Date") + " - " + rsNotes.getString("FollowUpNote"));
row.createCell(15).setCellValue(rs.getString("VisitID"));
}
}
}
catch(ClassNotFoundException cnf) {
out.print("<br> Error : MySQL Driver not found. <br>");
}
catch(Exception ex) {
out.print("Error : <br>" + ex);
}
%>
</body>
</html>
I'm getting this exception with Tomcat 6.0.26 :
exception
org.apache.jasper.JasperException: java.lang.NullPointerException
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:156)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
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:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
root cause
java.lang.NullPointerException
org.apache.jsp.GetReport_jsp.<init>(GetReport_jsp.java:29)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
java.lang.reflect.Constructor.newInstance(Constructor.java:513)
java.lang.Class.newInstance0(Class.java:355)
java.lang.Class.newInstance(Class.java:308)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:145)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
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:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
Did I miss something or anything wrong?
Can anybody help me to get rid of this problem?
Thanx in advance.
The way you are trying to do it doesn't make any sense. You can't mix HTML with Excel like that. Better create a servlet instead of a JSP page and let this servlet output only the Excel file and nothing else.
Something like this:
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
// ... plus all the other libs you need
public class ExcelServlet extends HttpServlet {
public void doGet (HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
HSSFWorkbook book;
// ...
// fill the book
// ...
res.setContentType("application/vnd.ms-excel");
book.write(res.getOutputStream());
res.getOutputStream().close();
}
}
HSSFWorkbook book;
HSSFSheet sheet;
HSSFRow row;
CreationHelper createHelper = book.getCreationHelper();
You are using the book object before initializing it.
I'd recommend not doing it this way.
Scriptlet code in JSPs is simply wrong.
Putting database access in a page like this isn't good, either.
A better approach would be Spring MVC and its JExcelView.
Here's a tip on how to debug JSP exceptions:
in the stacktrace, this class
java.lang.NullPointerException
org.apache.jsp.GetReport_jsp.<init>(GetReport_jsp.java:29)
is the generated java class for your GetReport.jsp. You can look in the $TOMCAT_HOME/work/<enginename>/<hostname>/<appname> folder to see the actual code generated, and see what exactly is at line 29.
Take a look at WorkbookTag project from SourceForge which does exactly what you need: HTML worksheet rendering using Apache POI... WorkbookTag