Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9007507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:42:31+00:00 2026-06-16T01:42:31+00:00

I have a jsp with this code snippet in it. <form name=AudioFileConversionForm enctype=multipart/form-data method=post

  • 0

I have a jsp with this code snippet in it.

<form name="AudioFileConversionForm" enctype="multipart/form-data" method="post" >
Choose File: <input type="file" id="audioFile" name="audioFile"><br>
<input type="submit" value="upload">
</form>

This is my controller in spring.

public String convertFile(HttpServletRequest request, HttpSession session) {

    String audioFile = request.getParameter("audioFile");
    System.out.println(request.getParameter("audioFile"));
    System.out.println("Audio File Conversion Successful");
}

I am unable to retrieve the name of the file, it shows null.
I know that I can retrieve the name using JQuery or javascript, but I don’t want to use them both. I want to do it using pure java.
Can anyone please help me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:42:33+00:00Added an answer on June 16, 2026 at 1:42 am

    When you upload the file, request is instance of org.springframework.web.multipart.MultipartHttpServletRequest. So you can cast it in your method convertFile(). See below :

    public String convertFile(HttpServletRequest request, HttpSession session) {
        // cast request
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        // You can get your file from request
        CommonsMultipartFile multipartFile =  null; // multipart file class depends on which class you use assuming you are using org.springframework.web.multipart.commons.CommonsMultipartFile
    
        Iterator<String> iterator = multipartRequest.getFileNames();
    
        while (iterator.hasNext()) {
            String key = (String) iterator.next();
            // create multipartFile array if you upload multiple files
            multipartFile = (CommonsMultipartFile) multipartRequest.getFile(key);
        }
    
        // logic for conversion
    }
    

    However I am unable to retrieve (receiving null value) the name of the file that I chose in the JSP page.

    —> To get file name you can get it as :

    multipartFile.getOriginalFilename();  // get filename on client's machine
    multipartFile.getContentType();       // get content type, you can recognize which kind of file is, pdf or image or doc etc
    multipartFile.getSize()          // get file size in bytes
    

    To make file upload work, you need to make sure you are creating multipart resolver bean as below :

    <bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    
        <!-- one of the properties available; the maximum file size in bytes -->
        <property name="maxUploadSize" value="100000"/>
    </bean>
    

    Reference : Spring documentation

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this JSP code snippet: <%@ taglib uri=http://java.sun.com/jsp/jstl/core prefix=c%> <c:choose> <c:when test=${var1.properties[\Item Type\]
I have a jsp file that contains this code, <form id=testForm> <input type=hidden value=study--study
I have some JSP code, which writes a tree representing hierachical data. This data
I have this code in my jsp file: <body> <c:if test=${!isActivityVP && isBuy &&
I have this code in my .jsp file: <%= formBean.getMonth() == default %> I
I have a jsp page which needs a java code. This java code inside
I have this jQuery code in my JSP page (jQuery 1.7.2) : function Header()
I have a jsp code like this <html:option value=${apealstaList.appealStatusMasterId} disabled=true>${apealstaList.appealStatusDescription}</html:option> This disable the options
I have picked up this code(DragandDrop.jsp) from this page :: http://jsfiddle.net/petersendidit/S4QgX/ I am getting
I have this nav code in multiple JSP files: <ul id=nav> <li ><a href=/home>Home</a></li>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.