I have a JSP page with two tabs and I am trying to run some Java code in the second tab but I keep getting a null pointer exception. I swear my Java Code is correct but the second tab wont show up either.
<%
String fn = request.getParameter("fn9");
String ln = request.getParameter("ln9");
String primaryEmail = request.getParameter("primaryemail9");
CreatingTheProviderFile ctpf = new CreatingTheProviderFile();
char[] c = fn.toCharArray();
if(fn != null){
System.out.println("it is blank");
}else{
System.out.println("it is something else");
}
if(fn != ''){
ctpf.FillNameArray(fn, ln, primaryEmail);
}
%>
JSP for some reason doesnt like the char statement nor does it like the if statement. This is my stacktrace
Dec 18, 2013 11:37:33 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/TwoWayPortal] threw exception [An exception occurred processing JSP page /patient_discharge.jsp at line 800
797:
798: // CreatingTheProviderFile ctpf = new CreatingTheProviderFile();
799:
800: char[] c = fn.toCharArray();
801:
802: System.out.println(c[0]);
803: // System.out.println(String.valueOf(fn.charAt(0)));
Stacktrace:] with root cause
java.lang.NullPointerException
at org.apache.jsp.patient_005fdischarge_jsp._jspService(patient_005fdischarge_jsp.java:999)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:205)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1852)
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:662)
I appreciate any help,
Thank You
The line that throws the NullPointerException is the line with fn.toCharArray(); This implies that fn is null.
Try
if(fn != null){
//do stuff here
}
Yes. fn is null.
// test for null, init to null if fn is null.
char[] c = (fn != null) ? fn.toCharArray() : null;
if (fn != null) {
System.out.println("it is not null");
if (fn.length() > 0) { // fn != '' is illegal, could have used !fn.equals("") -
// note double quotes (not single).
ctpf.FillNameArray(fn, ln, primaryEmail);
}
} else {
System.out.println("it is something else");
}
Before doing fn.toCharArray() check whether fn is null or not. You are checking it later. But if fn is null, you will get exception on fn.toCharArray() only and rest of the code wont execute.
When you change tabs, you may be losing data in request scope (just a guess). As an experiment, you can consider putting data in session scope instead. If it works, you may conider weather or not its of value to leave it as session scope.
Related
Following is the exact error.
Type Exception report:
message An exception occurred processing JSP page /FinancialAssessment.jsp at line 440
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 /FinancialAssessment.jsp at line 440
437:
438:
439:
440:
if(std.prev_treatment_start_date.equals("null"))
441: {
442: System.out.println("out by krishna------------");
443:
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.jsp.FinancialAssessment_jsp._jspService(FinancialAssessment_jsp.java:542)
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)
If your error line is that one on the if statement which is the most prabably, try this:
if( std == null || std.prev_treatment_start_date == null ) {
.....
This is because in java you have to test each object to avoid a NullPointerException which means that an object is null and cannot have methods or attributes.
Either std or std.prev_treatment_start_date is null. You should use:
if (std == null || std.prev_treatment_start_date == null) {
The way you wrote it means "std.prev_treatment_start_date is a string and has a value, and this value equals the string null".
Linux web server with nginx + resin4.0 pro, always throw error like this:
{http://*:8082-117} java.lang.NullPointerException
at com.caucho.server.http.HttpServletRequestImpl.getRemoteAddr(HttpServletRequestImpl.java:237)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:921)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:96)
at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:109)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
at com.caucho.server.cache.ProxyCacheFilterChain.doRequestCacheable(ProxyCacheFilterChain.java:245)
at com.caucho.server.cache.ProxyCacheFilterChain.doFilter(ProxyCacheFilterChain.java:188)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:156)
at com.caucho.server.webapp.AccessLogFilterChain.doFilter(AccessLogFilterChain.java:95)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:287)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:792)
at com.caucho.network.listen.TcpSocketLink.dispatchRequest(TcpSocketLink.java:730)
at com.caucho.network.listen.TcpSocketLink.handleRequest(TcpSocketLink.java:689)
at com.caucho.network.listen.TcpSocketLink.handleRequestsImpl(TcpSocketLink.java:669)
at com.caucho.network.listen.TcpSocketLink.handleRequests(TcpSocketLink.java:617)
at com.caucho.network.listen.AcceptTask.doTask(AcceptTask.java:104)
at com.caucho.network.listen.ConnectionReadTask.runThread(ConnectionReadTask.java:98)
at com.caucho.network.listen.ConnectionReadTask.run(ConnectionReadTask.java:81)
at com.caucho.network.listen.AcceptTask.run(AcceptTask.java:67)
at com.caucho.env.thread.ResinThread.runTasks(ResinThread.java:164)
at com.caucho.env.thread.ResinThread.run(ResinThread.java:130)
It may cause by older resin.jar. The code:
public String getRemoteAddr(){return _request.getRemoteAddr();}
This code is updated on 16 Jun 2012 and became:
public String getRemoteAddr(){AbstractHttpRequest request = _request; return request != null ? request.getRemoteAddr() : null;}
I'm new to drools and what I'm trying to do is to get a value from the rules
I used the code from the project sample of drools which is:
Reading the DRL file:
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newClassPathResource( "path.drl", getClass() ), ResourceType.DRL );
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if( errors.size() > 0 )
{
for( KnowledgeBuilderError error : errors )
{
System.err.println( error );
}
throw new IllegalArgumentException( "Could not parse knowledge." );
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
return kbase;
Inserting object and firing the rules
Bean bean = new Bean();
StatefulKnowledgeSession ksession = aKnowledgeBase.newStatefulKnowledgeSession();
// planning to insert a double
ksession.insert( bean );
ksession.fireAllRules();
What I want to do is to get a value from the rules, What I tried so far is using query which is I'm not sure if it is the proper way of doing it:
global String $test;
rule "Excellent"
when
// I'm planning to replace the bean with just a double is that possible?
$m: bean ( listeningScore > 85 )
$p: bean ( listeningScore < 101 )
then
$test = "Excellent";
System.out.println( $test );
end
query "Knowledge"
$result : $test
end
Also this produce an error which I really don't know how to fix. Here is the stacktrace:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[24,0]: [ERR 102] Line 24:0 mismatched input 'end' in query
[0,0]: Parser returned a null Package
java.lang.IllegalArgumentException: Could not parse knowledge.
at com.neu.als.thesis.units.InferenceEngine.readKnowledgeBase(InferenceEngine.java:61)
at com.neu.als.thesis.units.EvaluationUnit.evaluateConceptKnowledgeLevel(EvaluationUnit.java:187)
at com.neu.als.thesis.web.controllers.FLTController.evaluateFLT(FLTController.java:108)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:444)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:432)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:946)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:848)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:822)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Firstly, that exception means that the DRL code won't compile. I suspect this is because your query is referencing a bound variable from another rule, but it could be something else. Check out the docs on syntax for queries.
However, I tend to use one of two mechanisms for getting rule responses into the Java code.
In a stateless session have rules modify the inserted fact(s). After rules execution, just look at the fact that you inserted.
In a stateful session you can additionally use session.getObjects() or session.getObjects(ObjectFilter) to get references to the facts that are in the working memory after rules execution.
Here's an example of the first pattern, modifying the inserted fact:
rule "Reject a request"
when
$req: PaymentValidationRequest()
then
$req.setValid(false);
update($req);
end
PaymentValidationRequest request = new PaymentValidationRequest(payment);
request.setPayment(payment);
List<Object> facts = new ArrayList<Object>();
facts.add(request);
ksession.execute(facts);
...
boolean isValid = request.isValid()
List<ValidationAnnotation> annotations = request.getAnnotations();
Here's an example of the second pattern, when your rules have inserted or modified facts:
ObjectFilter filter = new ObjectFilter() {
#Override
public boolean accept(Object object) {
return object.getClass().getSimpleName().equals("MyFact");
}
};
for (FactHandle handle : session.getFactHandles(filter)) {
Object fact = session.getObject(handle);
// Do something with the fact you just found in working memory.
// ...
}
Following is my code which runs pigrunner and pigstats:
String[] args = {"abc.pig"};
PigStats stats = PigRunner.run(args,null);
System.out.println("Stats : " + stats.getReturnCode());
OutputStats os = stats.result("B");
Iterator<Tuple> it = os.iterator();
while(it.hasNext()){
Tuple t = it.next();
System.out.println(t.getAll());
}
Contents of abc.pig
A = load 'Courses' using PigStorage(' ');
B = foreach A generate $0 as id;
dump B;
I get the correct output but it is followed by this exception Stacktrace with root cause
org.apache.hadoop.mapreduce.lib.input.InvalidInputException: Input path does not exist: hdfs://localhost:54310/tmp/temp-221133443/tmp1478461116
at org.apache.hadoop.mapreduce.lib.input.FileInputFormat.listStatus(FileInputFormat.java:235)
at org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.PigFileInputFormat.listStatus(PigFileInputFormat.java:37)
at org.apache.hadoop.mapreduce.lib.input.FileInputFormat.getSplits(FileInputFormat.java:252)
at org.apache.pig.impl.io.ReadToEndLoader.init(ReadToEndLoader.java:154)
at org.apache.pig.impl.io.ReadToEndLoader.<init>(ReadToEndLoader.java:116)
at org.apache.pig.tools.pigstats.OutputStats.iterator(OutputStats.java:148)
at org.apache.jsp.result_jsp._jspService(result_jsp.java:86)
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.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)
Now the same code works without an error if I replace the DUMP with a STORE.
Can some please explain me what is going on ?
Thanks
Ravi
In case of dump Pig stores the output at a temporary location, e.g: hdfs://localhost/tmp/temp797130848/tmp1101984728
(have a look pig.map.output.dirs in your job's config.xml)
PigRunner.run() calls GruntParser.processDump(String alias) at some point of the process which iterates through the result tuples and prints them out to the console:
Iterator<Tuple> result = mPigServer.openIterator(alias);
while (result.hasNext())
{
Tuple t = result.next();
System.out.println(TupleFormat.format(t));
}
After this, but before returning, it also calls FileLocalizer.deleteTempFiles() which deletes this temporary directory.
Now you want to return the result of alias B.
OutputStats's iterator tries to open the temporary file again to loop over the tuples as PigRunner.run() did it before.
But the problem is that this file doesn't exist anymore, therefore your get the exception.
So I'd suggest you to remove the code after System.out.println("Stats : " + stats.getReturnCode()); since you already have the dump printed out.
I am building a web application for feature extraction and comparing the feature of images, using JSP, Java, and PostgreSQL.
My feature extraction is extracting some features from images, so that then I can compare them (some features are about color, some on the histogram of the image and so. I have special methods that extract them using specific libraries (jars that I add into lib) as you can see in the following example!
Those features are then successfully being added into my PostgreSQL database.
public void GetImageProperties(String targetPath, ImageProperties imagesProperties) throws Exception
{
// load image
FileInputStream imageStream;
imageStream = new FileInputStream(targetPath);
BufferedImage bimg = ImageIO.read(imageStream);
// get properties
imagesProperties.cl = new ColorLayoutImpl(bimg);
imagesProperties.eh = new EdgeHistogramImplementation(bimg);
imagesProperties.sc = new ScalableColorImpl(bimg);
}
Then I add them into a postgresql database(only the features, not the images)
String query = "CREATE TABLE Images (" +
" imageid SERIAL PRIMARY KEY," +
" fname VARCHAR(128)," +
" colorlayout VARCHAR(512), " +
" edgehist VARCHAR(512), " +
" scalablecolor VARCHAR(512) " +
")";
I get this error every time I had loaded an image and want to compare it with all the other images in a directory.
HTTP Status 500 -
type Exception report
message:
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 /query.jsp at line 124
121: if (bSearch) {
122: // get form params
123: query.setTopK(new Integer(request.getParameter("frm_topk")));
124: query.setColorHistogramWeight(new Integer(request.getParameter("frm_weight_c1")));
125: query.setColorDistributionWeight(new Integer(request.getParameter("frm_weight_c2")));
126: query.setTextureWeight(new Integer(request.getParameter("frm_weight_c3")));
127: }
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:722)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
root cause:
java.lang.NumberFormatException: For input string: "1.0"
java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
java.lang.Integer.parseInt(Integer.java:492) java.lang.Integer.<init>
(Integer.java:677) org.apache.jsp.query_jsp._jspService(query_jsp.java:256)
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.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.27 logs.
Your problem is here
query.setTopK(new Integer(request.getParameter("frm_topk")));
should be
String parFrm_topk = request.getParameter("frm_topk");
Integer frm_topk = null;
if (parFrm_topk != null && parFrm_topk.length() > 0 && !parFrm_topk.equals("null"))
try {
frm_topk = Integer.valueOf(parFrm_topk);
} catch (NumberFormatException nfe){
throw nfe;
}
if (frm_topk ! = null) {
query.setTopK(frm_topk);
this code is trying to check the parameter that could be empty, why it is empty depends on how flow the app and how parameters are passed through url.