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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:22:10+00:00 2026-05-12T10:22:10+00:00

In MVC (such as JSP and Spring), is it bad practice to view related

  • 0

In MVC (such as JSP and Spring), is it bad practice to view related code in the controller?

In my case, the controller does some work and then hands off the results to the view (JSP). In the case of a status message, I can pass the entire message text to the view, or pass a key and let the JSP map it to the message text.

Example:

Message generated in controller

Spring Controller:

protected ModelAndView onSubmit(...) {
    Map map = new HashMap();
    // Controller processing
    if (...)
        map.put("status", "Case 1 status message");
    else
        map.put("status", "Case 2 status message");
    return new ModelAndView("viewPage", map);
}

JSP:

{$status}

Message generated in view

Spring Controller:

protected ModelAndView onSubmit(...) {
    Map map = new HashMap();
    // Controller processing
    if (...)
        map.put("status", "case1");
    else
        map.put("status", "case2");
    return new ModelAndView("viewPage", map);
}

JSP:

<c:choose>
  <c:when test="{$status eq 'case1'}">Case 1 status message</c:when>
  <c:when test="{$status eq 'case2'}">Case 2 status message</c:when>
</c:choose>

In the first case, the controller and JSP code is simpler, but there’s view related logic in the controller.
In the second case, all view logic is in the JSP, but the code isn’t as simple.

Am I violating MVC paradigm by generating message text in the controller? What is the common practice for this scenario?

  • 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-12T10:22:10+00:00Added an answer on May 12, 2026 at 10:22 am

    Combining UI and Controller code in MVC is common practice in Rich Clients (in Swing for example). even in web MVC it is sometimes implemented, for very simple responses.

    In your case however what you are doing is not recommended. Usually you put the texts of your application in a resource bundle using spring’s MessageSource mechanism, and refer to it only using codes. The resource bundle is a simple properties file, in your case it will look like this:

    case1=Case 1 status message
    case2=Case 2 status message
    

    In the JSP you refer to it using the tag in the following manner:

    <spring:message message="${status}"/>
    

    Resource bundles have two advantages:

    • It is easy to internationalise your site and provide it in multiple languages
    • You can manage the application texts externally to the source, and if you use spring’s ReloadableResourceBundleMessageSource you can even change the texts without re-deploying the application.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a spring MVC application using JSP as my view technologies with Jquery
I have a Spring MVC-Controller which generates some some kind of Byte-Response, which is
Spring MVC creates some default out of the box Objects such as HandlerMapping, ViewResolver
Spring MVC uses a DispatcherServlet to route control to an appropriate Controller. But where
Where in the Spring-MVC/JSP application would you store things that need to be accessed
In Spring 3 MVC, I have a controller that I call SettingsController, and it
I'm using HibernateValidator to validate forms in JSP using Spring MVC 3.0.2. Earlier, I
I'm developing an application in JSP using SimpleFormController with Spring MVC 3.0.2 using Hibernate.
I am using Spring MVC with such definition: <servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping>
Almost every new Java-web-project is using a modern MVC-framework such as Struts or Spring

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.