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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:16:57+00:00 2026-05-13T10:16:57+00:00

I have the following controller @Controller @RequestMapping(/project/view.html) public class ProjectViewController { private static final

  • 0

I have the following controller


@Controller
@RequestMapping("/project/view.html")
public class ProjectViewController {

 private static final String viewName = "projectView";


 @RequestMapping(method = RequestMethod.GET)
 public String showPage(Model model,
   @RequestParam(value="id",required=false) Long id) {

  //code.....

  return viewName;
 }

}

My views.properties contains


projectView.(class)=org.springframework.web.servlet.view.JstlView
projectView.url=/WEB-INF/jsp/project/view.jsp

Everything works as expected.

But I needed to change the method to return a View(), cause I have to return a RedirectView() to some error page if something fails. So I’ve changed the method to:


@Controller
@RequestMapping("/project/view.html")
public class ProjectViewController {

 private static final String viewName = "projectView";


 @RequestMapping(method = RequestMethod.GET)
 public View showPage(Model model,
   @RequestParam(value="id",required=false) Long id) {

  //code.....

  return new JstlView(viewName);
 }

}

But in this case I get a NPE :


java.lang.NullPointerException
 at org.springframework.web.context.support.WebApplicationObjectSupport.getServletContext(WebApplicationObjectSupport.java:121)
 at org.springframework.web.servlet.view.JstlView.exposeHelpers(JstlView.java:133)
 at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209)
 at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:257)
 at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1183)
 at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:902)
 at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
 at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
 at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
 at com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
 at java.lang.Thread.run(Thread.java:619)

I’ve debugged and it seems that getWebApplicationContext() returns null.

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-05-13T10:16:57+00:00Added an answer on May 13, 2026 at 10:16 am

    The cause of your exception is that instances of JstlView need to be injected with certain things before they can be used, for example the current WebApplicationContext. Normally, this is transparent to you, because Spring instantiates and prepares JstlView for you. It’s only when you do it yourself, that you see what’s involved.

    Now, you could call setApplicationContext on the JstlView that you instantiate, but you don’t want your controllers getting involved in that sort of thing. You really want to keep Spring doing the work.

    Now, since you’re using views.properties, it follows that you’re also using ResourceBundleViewResolver to resolve your views. The trick here is to realise that Spring can handle multiple view resolvers in the same context, it’ll simply ask them one after the other, until one of them resolves the view name.

    So my suggestion would be to add another resolver to your context, this time an InternalResourceViewResolver (this is actually the default resolver, but that default is suppressed when you specified your ResourceBundleViewResolver).

    Now, when you return a view name that the ResourceBundleViewResolver can’t resolve, the InternalResourceViewResolver will be consulted.

    InternalResourceViewResolver just takes the view name as the actual JSP path (e.g. return /WEB-INF/page.jsp directly from your controller method). It also lets you use syntax like redirect:/path/to/my/url.

    So yours other controllers can keep on returning view names as specified in views.properties, but now in addition you can return dynamically-assembled redirect:x/y/ view names, which will be translated by InternalResourceViewResolver into a RedirectView. No need to construct these views yourself.

    One last point to note: the view resolvers are consulted in the order in which they appear in the beans file, and InternalResourceViewResolver must come last in that list.

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

Sidebar

Ask A Question

Stats

  • Questions 297k
  • Answers 297k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Remove height:35px; from li.headlink and it will work. May 13, 2026 at 7:21 pm
  • Editorial Team
    Editorial Team added an answer I think you can solve this using the dynamic programming… May 13, 2026 at 7:21 pm
  • Editorial Team
    Editorial Team added an answer I don't think you can map an ICollection. Regardless, I'm… May 13, 2026 at 7:21 pm

Related Questions

I have a controller class as in the following code segment: @Controller public class
I have the following controller action and test. I'm new to testing with Shoulda
I have the following code wrapped by swig: int cluster::myController(controller*& _controller) { _controller =
I've read a lot of Zend controller testing tutorials but I can't find one
I am working on the admin section of a new rails app and i'm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.