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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:52:55+00:00 2026-06-03T03:52:55+00:00

I am trying to learn Spring framework by building simple website, now I have

  • 0

I am trying to learn Spring framework by building simple website, now I have a problem.

I would want to make something like this: user chooses which file to upload and chooses from a list what type of file it is. For now I have something like this:

<form:form modelAttribute="uploadItem" method="post" enctype="multipart/form-data">
<fieldset>
    <div class="form_elem">
        <label for="file">File</label> 
        <input type="file" name="fileData"/>
</div>
<div class="form_elem">
        <label for="file_type">File type</label> 
        <form:select path="fileType">
                    <form:options items="${fileTypes}" />
        </form:select>
</div>
<input type="submit"/>
</fieldset>

now in my controller I have

@RequestMapping(value = "/addWordFile", method = RequestMethod.GET)
public String showFileAdder(Model model) {
    model.addAttribute(new UploadItem());
    model.addAttribute("fileTypes", Arrays.asList("first type", "second type"));
    return "questionFileAdd";
}

@RequestMapping(value = "/addWordFile", method = RequestMethod.POST)
public String processUploadedFile(UploadItem uploadItem, Model model)
        throws Exception {
    String type=uploadItem.getFileType();
    return showFileAdder(model);
}

here is the problem, when user chooses type of the file, I get only a String and I would need to manually create an object, like SimpleFileFileReader using class for name or just using big switch-case statement for every type of file I support.

Is it possible to show String in html form, but when it is processed I would get an object of some class?

  • 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-03T03:52:56+00:00Added an answer on June 3, 2026 at 3:52 am

    This is rather an OO question than a Spring question. What you want is a factory of SimpleFileReader. Simply using a Map<String, SimpleFileReader> could be your solution:

    • the keySet() of the map contains all the file types
    • once you get the file type from the GUI, use map.get(fileType) to get the SimpleFileReader associated to this type

    You could also use en enum:

    public enum FileType {
        TYPE_1 {
            public SimpleFileReader getFileReader() {
                return new Type1SimpleFileReader();
            }
        },
    
        TYPE_2 {
            public SimpleFileReader getFileReader() {
                return new Type2SimpleFileReader();
            }
        };
    
        public abstract SimpleFileReader getFileReader();
    }
    

    The FileType.values() gives you the array of file types. Spring can automatically map an input field to an enum, and getting the associated file reader is as simple as

    SimpleFileReader reader = fileType.getFileReader();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to learn about php's arrays today. I have a set of arrays like
I'm trying to learn Spring MVC 3.0 and I made a simple web to
I was trying to learn a little about JAVA frameworks like Spring. I hit
trying to learn and practice arrays but I have a problem with this small
im trying to learn some jsp as well as the spring framework. My application
In short, I'm trying to learn a bit of Spring. Problem is, when I
I am trying to learn regex. I have the string: $x = 5ft2inches; How
In trying to learn how to create objects in ActionScript, I have had no
Im trying to learn a bit about c++ and have run in to some
I've been trying to learn GWT for quite a while, I want to build

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.