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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:34:54+00:00 2026-06-08T15:34:54+00:00

I try to solve the following problem: I have set up my own viewResolver,

  • 0

I try to solve the following problem:

I have set up my own viewResolver, adding a header and footer to all my requests (thanks, stackoverflow ;p). This works fine.

Problem is that my ajax-requests, that return a view to a specific container, also automatically get the header and footer which of course is not intended.

How can I get the viewResolver to act different if a request contains ‘/ajax/’? Actually, the jstl-Viewer works fine for them, but at the moment, my own resolver is the only one used because I don’t know how to tell spring to act different on ‘/ajax/’.

Here my own resolver, pretty simple, just taken from here:

public class ViewTemplate extends InternalResourceView {
    @Override
    protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
        String dispatcherPath = prepareForRendering(request, response);
        request.setAttribute("partial", dispatcherPath.substring(nthOccurrence( dispatcherPath, '/' , 2 ) + 1));

        RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/views/layout.jsp");
        rd.include(request, response);
    }

    // more functions like nthOccurrence


}

Do I have to tell this resolver that if indexOf(“/ajax/”) != -1 jstView needs to be called? And if yes, how?
Or am I doing it completely wrong? I would like to keep my header/footer as they are for all non-ajax-requests!

Any help appreciated!

Thanks!

  • 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-08T15:34:55+00:00Added an answer on June 8, 2026 at 3:34 pm

    You have put the code for a View not a ViewResolver right, I think a good solution could be to chain the ViewResolvers – just declare a new ViewResolver for your ajax views. For the Ajax related views, let this view resolver return a value, else return null, this will automatically get the ViewResolver to consider the next ViewResolver in the chain which can be your current ViewResolver.

    eg.

    <beans:bean id="ajaxViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="order" value="1"></beans:property>
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="viewNames">
            <beans:list>
                <beans:value>ajax*</beans:value>
            </beans:list>
        </beans:property>
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>
    

    In the above case, if you return your view name from a controller as “ajaxsomeview” then it will be handled by ajaxViewResolver, if you return “somethingelse” it will be handled by your current ViewResolver.

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

Sidebar

Related Questions

I have to solve the following optimization problem: Given a set of elements (E1,E2,E3,E4,E5,E6)
I have looked all over the internet to try and solve this problem. Can
I have a strange problem that I could not solve. When I try to
I have following problem and only could solve it partially yet. I am working
I'm trying to solve the following real-life problem you might have encountered yourselves: You
thanks allready for helping me out with this. The following problem occurs: I have
I try to solve this problem several times and give up. Now, when I
I have the following problem. I have an object with some DateTime properties ,
I have a problem with compatibility, I think... Following the Panoramio API Reference Guide
I have the following code: def causes_exception(lamb): try: lamb() return False except: return True

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.