• Post Reply Bookmark Topic Watch Topic
  • New Topic

File object

 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String s12=request.getParameter("image");


File imgfile = new File(s12);

then it shows error
java.lang.NullPointerException
java.io.File.<init>(Unknown Source)
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
request.getParameter("image") will return null if there is no parameter "image" in it.
 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no it return abstract path because i made it
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
amrita singhal wrote:no it return abstract path because i made it

I don't know what that is supposed to mean. But it's clear from the stack trace that you are passing null to the File constructor.
 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i create an input tag with file type named "image" in a page
now in this page i got the value using "image" name with getParameter function
as i wrote earlier
s12 returns the path that i will supplied in input tag
here it is images/11.jpg in s12

but when i wrote it in file type object it shows

java.lang.NullPointerException
java.io.File.<init>(Unknown Source)
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you created an input tag with its type as file, you can't get it via getParameter.
Are you trying to upload a file?
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At this point you need to post your all your code.
 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in a.jsp
<form action="b.jsp" method="post">
<table border=0>
<tr>
<td >Upload your Image</td>
<td >
<input type="file" name="image" id="image"></td>

</tr>

<tr>

<td ><input ></td>
</tr>


</table>
</form>


in b.jsp
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<%
String s12=request.getParameter("image");
File imgfile = new File(s12);

FileInputStream fin = new FileInputStream(imgfile);
%>



now it shows error on

java.lang.NullPointerException
java.io.File.<init>(Unknown Source)>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.

Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.

2) You can't use File I/O to access a file on the client. See the JSP FAQ for the ways that file uploading must be handled.
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you explain how your code sets the "image" parameter in the request object?
 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i typed image path(complete) at run time
i want to get that path so i used request object
in s12 it shows absolute path of that i gave earlier
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I meant was please point out the line in your code that sets the "image" parameter in the request object?
 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String s12=request.getParameter("image");
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is all moot.

What it comes down to is that if you want to upload the file from the client to the server you are approaching it completely incorrectly. You can't just get the name of the file and expect the server to be able to read it from the client. Can't happen.

Please see the JSP FAQ entry on file uploading. Anything else is just a waste of your time and everybody else's.
 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to store file in database through upload
not load on server
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a minor point. Read the FAQ, the process of reading the contents of the file will be the same. What you do with them once you have them is up to you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!