Hi everyone. I'm really confused as to how can I run my java program inside JSP.
My JSP project is a subscription form. Upon completion of the subscription form, when the user click on the submit button. It will initiate a file download(java file) to the specified path inside the java file.
Some of the methods which I've heard to make it possible to run is to 1) modify my Java program to a Servlet. 2) modify my Java program to an Applet. 3) just insert the java code into the jsp project and run it.
I've tried 2nd and 3rd method, somewhow there's some error in it. Am I heading in the right direction? Or What could I do to resolve this? Please advice.
You can use scriptlet inside your JSP, but it's not recommended, though. According to MVC architecture, you're better off dispatching your request from your JSP to a servlet and let the servlet call your business logic (your download method).
SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
Hi everyone again.. There's something weird going on..
I did manage to download the file . However, the file wasn't downloaded to the machine that has completed the subscription form. Instead, It went to the Server machine that is hosting the JSP. :shocked:
I've checked through the program and can't seem to find anything wrong.
I'm running the JSP file from Oracle JDeveloper 10(as a server). For client, it's running fedora core 6 system.
Would appreciate if someone can point out where I can start looking to resolve this problem. Sorry for the trouble and Thank you very much!
Joined: Mar 22, 2005
Can you explain what the code is supposed to do?
It uses System.in, which in a servlet container is unlikely to do anything useful. I'm also not sure what the sockets are for.
Can't you just stream the file to the client through the HTTP response? An example of that can be found here.
Joined: May 10, 2007
Hi Ulf. I'll give a short description on the project.
Server : 1) Will be running server.java(Opens up a socket for client to get file). 2) testbg.gif(file for client to download) is stored on the desktop 3) Will be running login.jsp from Oracle JDeveloper.
Client : 1) Client does his subcription form on his own pc(fedora core 6) through ip address. 2) Upon completion, client.java(servlet) will initiate a file download from server side. 3) Client does not need to state the path to save the file.
My main aim is to let the client complete the subscription form and download the file(42kb size) at the end. Client do not have to state where to save the file. The actual file that i would like to send is a GUI bundle.
I've run the file streaming sample. I'm just wondering if it will be able to download the file directly to the clients' pc without clients' need to choose the file location. Would that be a problem?
Many thanks for your help. [ September 27, 2007: Message edited by: Adrian Lee ]
Ok, you want to download and save a file on the client computer? In a place you specify and the user can not change?
Can not be done with JSP/Servlet technology. To allow this sort of ability would be a serious security breach on a computer. Just by visiting a webpage it downloads a file somewhere on your computer without your being able to do anything about it?
With JSP/Servlet, the java code is running on the SERVER. Not on the clients computer. So you can access the file system on the server - it won't help you to put a file on the client.
Two suggestions 1 - Just send the file to the client, and have them select where to save it. (Standard HTTP limitations) 2 - Use a signed applet which will then have access to the local client file system, and you can deal with it in that way.