Upload File - JSP + Servlet + Netbeans
Hello all,
I'm traing to make a example web application in Netbeansw 6.8 to do the follow task, send a file from Web Client Browser to server. I use Glassfish 2.x as J2EE server web application with apache. The web page is a JSP with woodstock components. I have done the servlet, and the web page, but the main question is the way to call the servlet from the jsp web page form when this is submited to de server making a POST.
Some one as an little example where I can see the way it works.
Thank you very much
Oscar
Re: Upload File - JSP + Servlet + Netbeans
Hi,
For file uploading you have to use enctype="multipart/form-data" attribute in form tag.
and have to provide the path to servlet in action.
Then have to use a input filed with type file.
Then you will get the file in servlet
bean factory
Re: Upload File - JSP + Servlet + Netbeans
This is the tutorial I've been following: FileUpload - Using FileUpload
Re: Upload File - JSP + Servlet + Netbeans
Hi,
Please check the code bellow for servlet if that can help you:
f (ServletFileUpload.isMultipartContent(request)) {
ServletFileUpload servletFileUpload = new ServletFileUpload(
new DiskFileItemFactory());
List multiParts = servletFileUpload.parseRequest(request);
FileItem fileItem = null;
Iterator iterator = multiParts.iterator();
while (iterator.hasNext()) {
try {
fileItem = (FileItem) iterator.next();
logger.debug("File item - " + fileItem.getFieldName());
if (fileItem.isFormField()) {
if (fileItem.getFieldName().equals("param")) {
}
}else{
//write code for file
}
Re: Upload File - JSP + Servlet + Netbeans
Quote:
Originally Posted by
mr.miku
Hi,
Please check the code bellow for servlet if that can help you:
f (ServletFileUpload.isMultipartContent(request)) {
ServletFileUpload servletFileUpload = new ServletFileUpload(
new DiskFileItemFactory());
List multiParts = servletFileUpload.parseRequest(request);
FileItem fileItem = null;
Iterator iterator = multiParts.iterator();
while (iterator.hasNext()) {
try {
fileItem = (FileItem) iterator.next();
logger.debug("File item - " + fileItem.getFieldName());
if (fileItem.isFormField()) {
if (fileItem.getFieldName().equals("param")) {
}
}else{
//write code for file
}
How is that better than simply sending them to the tutorial that contains pretty much identical code, as well as links to the libraries required to run it?