Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Upload File - JSP + Servlet + Netbeans

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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


  2. #2
    Junior Member
    Join Date
    Oct 2011
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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
    Last edited by abani; December 18th, 2011 at 02:02 AM.

  3. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Upload File - JSP + Servlet + Netbeans

    This is the tutorial I've been following: FileUpload - Using FileUpload
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    Member
    Join Date
    Nov 2011
    Posts
    37
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default 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
    }

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Upload File - JSP + Servlet + Netbeans

    Quote Originally Posted by mr.miku View Post
    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?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. file upload size limit
    By shiv@P in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: December 24th, 2012, 11:50 PM
  2. File upload problem
    By antonic in forum Web Frameworks
    Replies: 2
    Last Post: September 28th, 2011, 07:25 PM
  3. HOW TO UPLOAD JAVA FILES IN NETBEANS
    By ordonezc78 in forum Java IDEs
    Replies: 2
    Last Post: March 19th, 2011, 09:05 AM
  4. Want to upload csv file of greter than 200 Mb
    By shreyansh in forum Java Servlet
    Replies: 6
    Last Post: February 8th, 2011, 07:43 PM
  5. how to write servlet nd jsp prog. in netbeans
    By javaking in forum Java IDEs
    Replies: 1
    Last Post: December 20th, 2010, 10:12 PM

Tags for this Thread