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

  • Home
  • SEARCH
  • 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 3623788
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:25:36+00:00 2026-05-18T23:25:36+00:00

I’m a php programmer now doing a Java web project using Spring framework. I’m

  • 0

I’m a php programmer now doing a Java web project using Spring framework. I’m trying to organize my JSP files the way i would have organized my .tpl files in php.

So if it would have been php i would have done it like this:

  • index.tpl
    • includes one of layout.tpls (ajax.tpl, mobile.tpl, general.tpl, simplified.tpl . . .)
      • includes the header of the page
      • includes menus
      • includes the actual content of the page
      • includes the page footer

then from the php controller i would be able to do something like this:

setLayout('general');
showTopMenu(false);
setContent('mySexyPage');

beside that i would have organized my stuff so that my views (tpl files) will be organized in folderы each corresponding to a single controller. like this:

  • userManager
    • addUSer.tpl
    • editUser.tpl
    • editUserPermissions.tpl
  • articleManager
    • addArticle.tpl
    • editArticle.tpl

and in each controller somehow define from which folder to load my content template.

Now in Spring i have a controller with methods handling requests and each of the methods returning what the view should be. I can extend all my controllers from a single abstract class where i will create an instance of ModelAndView with all default values set, then request handling methods will add what they need to the instance their daddy already created and return it.

The problem with the above approach is that i’m not forcing the coder who’s writing controllers to use the ModelAndView object i created, he way still return anything he wants from the handling method he wrote.

Is there some interface containing a method like ModelAndView getModelAndView() my daddy controller will implement so Spring will ignore whatever handler methods are returning?

Or is there some better way to do this ?

  • 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-18T23:25:37+00:00Added an answer on May 18, 2026 at 11:25 pm

    Content Template Issue

    The Java world has a (more than one actually, but I’m sticking with the one I know) solution for this problem, it is called Tiles. check out section 16 of the Spring 3.0.5 Reference.

    ModelAndView Issue

    This is more interesting. First, you can use Model with out view and have your controllers just return the view name (i.e. return a String). I believe you want to create the initial Model somewhere. Then have each controller hander method accept an argument of type Model.
    Here is what I tend to do (no claim that it is a best practice):

  2. Have a Controller.get(Model model) method that sets the initial values.
    
    @RequestMapping(method = RequestMethod.GET)
    public String get(Model model)
    { ... set default stuff ... }
  3. Every Handler method is a variation of this:
    
    @RequestMapping(value = "/search", method = RequestMethod.POST)
    public String search(Model model, ... other stuff as needed ...)
    { ... set stuff in model ... }
    
  • 0
  • Reply
  • Share
    Share
    • Share on Facebook
    • Share on Twitter
    • Share on LinkedIn
    • Share on WhatsApp
    • Report

Sidebar

Related Questions

No related questions found

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.