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 6531321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:51:50+00:00 2026-05-25T09:51:50+00:00

I am new to Spring MVC though not new to Java and working primary

  • 0

I am new to Spring MVC though not new to Java and working primary on Struts2 and Wicket as my choice for web development

I am trying to do a POC of file upload using spring MVC here is my jsp file

<form  id="fileuploadForm" action="fileupload" method="POST" enctype="multipart/form-data" >
            <fieldset>
                <legend>Upload Fields</legend>

               <input id="file" type="file" name="file" />
                <p><button type="submit">Upload</button></p> 

            </fieldset>
        </form>

and my Controller is

@Controller
@RequestMapping("FileUpload/fileupload")
public class FileUploadController{



    public ModelAndView processUpload(@RequestParam MultipartFile file, WebRequest webRequest, Model model) {


        String orgFileName = file.getOriginalFilename();
        String filePath = "data/input" + orgFileName;
        ModelMap modelMap = new ModelMap(); 
        System.out.println("*******************************************");
        File dest = new File(filePath);
        try {
            file.transferTo(dest);
        } catch (IllegalStateException e) {
            e.printStackTrace();
            modelMap.addAttribute("result", "File uploaded failed:" + orgFileName);
            return new ModelAndView("results", modelMap);
                //return "File uploaded failed:" + orgFileName;
        } catch (IOException e) {
            e.printStackTrace();
            modelMap.addAttribute("result", "File uploaded failed:" + orgFileName);
            return new ModelAndView("results", modelMap);
        }


        modelMap.addAttribute("result", "File uploaded " + orgFileName);
        return new ModelAndView("results", modelMap);



    }

below is the entry for dispatcher-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:security="http://www.springframework.org/schema/security"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">

     <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />
     <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver"
         p:suffix=".jsp" />

    <bean name="/*" class="com.app.controller.FileUploadController"/>
</beans>

i tried google also but not able to get any help may be not able to find good resource due to lack of knowledge of spring MVC
where ever i am hitting my uplaod button i am getting 404 error for this URL

http://localhost:7777/FileUpload/fileupload

i am sure i am doing some configuration mistake but not able to point it out, any help in this will be very helpful

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>SpringExample17</display-name>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>WEB-INF/dispatcher-servlet.xml</param-value>
    </context-param>
    <listener>
        <listener-class>
        org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.htm</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>    
</web-app>

Thanks in advance

  • 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-05-25T09:51:50+00:00Added an answer on May 25, 2026 at 9:51 am

    There are several things to note:

    • You have mapped only URLs ending on .htm to your Spring Dispatcher, so the Controller can never see your request.
    • If FileUpload is the name of your Web-App, you need to remove it from the @RequestMapping annotation.
    • <bean name="/*" class="com.app.controller.FileUploadController"/> should be changed to <bean name="/fileupload.htm" class="com.app.controller.FileUploadController"/>

    HTH

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

Sidebar

Related Questions

Almost every new Java-web-project is using a modern MVC-framework such as Struts or Spring
I am new to Spring MVC. But I had certain experience in working with
I am writing Web app in java using Spring Web MVC framework. Somehow validation
We are working on a Spring 3.0.5 Web MVC-based application. In our code we
I am new to working with Spring on regular basis so I had a
I am fairly new to MVC and am really trying to a get used
I'm making a Web Service using Spring MVC. Controllers are called directly by the
I am new in spring mvc3,and I am trying to create a simple project
I am very new to spring and java. I have been using mostly springsource.org
I'm fairly new to real world MVC / .NET development (i've been studying MVC

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.