tags:

views:

582

answers:

3

Hi,

I need to read a file from the local file system using JSP, save it as a string , and send it to a webservice(deployed using glassfish) for processing. Can anyone suggest how to perform File IO using JSP?

Thanks, Deepak.

+2  A: 

Doing File I/O from a JSP is the same as doing it normally: Just use the java.io or java.nio classes. If you need to map a virtual path to a real one, you can use ServletContext#getRealPath.

T.J. Crowder
+1  A: 

Technically, I tend to agree with T.J. here. But actually its not the same, its a bad idea altogether.

Adeel Ansari
Why did you add `java-ee` tag to all `jsp`-tagged questions wherein you have answered? Please remove the `java-ee` tag. It's inappropriate in pretty much all of the questions which you retagged (and didn't retag yet, there are thousands of JSP/Servlet/JSF/JSTL/EL/JPA/etc questions without `java-ee` tag). If you disagree, please open a topic at meta.stackoverflow.com to discuss the rationale behind this retagging.
BalusC
@BalusC: I did it, because its all related to `java-ee`, apparently. JSP is a part of `JavaEE`, none the less. And if you notice there always been a `java` tag already. Which means its related to Java. But the question is SE or EE? So, I tend to make it clear that its EE. Hence, it would help people finding JSP question as well, when actually looking for JavaEE. In case you still find my argument lame. We can have opinion of other folks on that.
Adeel Ansari
Post a question/discussion/retag-request in meta.
BalusC
@BalusC: Right now reviewing `java-ee` tags, to see what kinda of question we got there, if not JSP. Then I will consider rolling back all, or at least where its not suitable. Thanks for your noticing. I believe, its good to review once before starting any discussion in order to make some reasonable argument. I hope you are okay with this approach.
Adeel Ansari
+1  A: 

If you want to upload a file to the server and process it, then use a html form with fileupload field and select the text file and submit the form . the file will be uploaded to the server where you can process it

http://www.java-tips.org/java-ee-tips/javaserver-pages/uploading-file-using-jsp.html

Sreejith