Reputation: 458
I want to add a file uploader to my JSP page. Inside the JSP, it returns a new page containing text (result). Is there a way to print the text in the current page I want to print that in a <div>
?
Upvotes: 0
Views: 2291
Reputation: 718768
Here is an example to get you started: http://www.java-tips.org/java-ee-tips/javaserver-pages/uploading-file-using-jsp.html
For the rest of it, I can't figure out what you are asking.
FWIW, it is not a great idea to do this kind of thing in JSP. It is better to put your business logic in a servlet and use JSPs just for rendering the output.
@BalusC's answer sketches how you would implement this the right way ... using a servlet and a JSP.
Upvotes: 1
Reputation: 1108692
Just submit to a servlet which forwards back to the same JSP with the result.
E.g. this /upload.jsp
<form action="upload" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" />
</form>
<div>${result}</div>
with a servlet which is mapped on an URL pattern of /upload
and does the following in doPost()
method:
// (process file upload)
// ...
request.setAttribute("result", "File upload finished!");
request.getRequestDispatcher("/upload.jsp").forward(request, response);
This way the message "File upload finished!"
will be available by ${result}
in the JSP and printed as such.
Upvotes: 0