Forums Register Login

Image uploading problem

+Pie Number of slices to send: Send
hello friends ,

i am trying to upload image and save it to mysql database
but don't no why it is giving the null pointer exception ..

please help me to solve this



following is the html code

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="InsertImage" method="post" enctype="multipart/form-data">
Select Image :- <input type="file" name="imageName" />
<input type="submit" value="Save Image" >
</form>
</body>
</html>

following is the servlet code

following is the console for null pointer exception


java.lang.NullPointerException
at com.demo.image.InsertImage.doPost(InsertImage.java:59)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
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:503)
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:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

 
+Pie Number of slices to send: Send
Your exception says that the problem happened at InsertImage.java:59. So go and put logging statements just before line 59 in your code and print all the values of the variables are used at line 59. This will let you know what is null.
+Pie Number of slices to send: Send


this is the line no 59 .
which is giving null pointer exception
+Pie Number of slices to send: Send
Is your servlet marked as @MultipartConfig?
+Pie Number of slices to send: Send
No
how to do that ?

can you please suggest ?
+Pie Number of slices to send: Send
You add the annotation at the top of your servlet class or you can use an xml config See here
+Pie Number of slices to send: Send
 

E Armitage wrote:You add the annotation at the top of your servlet class or you can use an xml config See here



Thank you for your help
+Pie Number of slices to send: Send
And just to preempt another Null Pointer problem, you are doing pst.setBlob before you create the PreparedStatement.
The problems of the world fade way as you eat a piece of pie. This tiny ad has never known problems:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 646 times.
Similar Threads
Storing images in database
PDF save in Browser?
how to display image with data in jsp page
NullPointerException
Select Tag Problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 22:50:51.