---
title: "Why spring MVC optionally returning no view in a single mapping"  
description: "Why spring MVC optionally returning no view in a single mapping"  
author: "Anonymous User"  
published: 2015-02-02  
updated: 2015-02-02  
canonical: https://www.mindstick.com/forum/12933/why-spring-mvc-optionally-returning-no-view-in-a-single-mapping  
category: "asp.net"  
tags: ["asp.net mvc"]  
reading_time: 1 minute  

---

# Why spring MVC optionally returning no view in a single mapping

I have a case where i need to :

- Return a 304 not modified [status](https://www.mindstick.com/articles/157184/check-lic-policy-status-online-by-policy-number) if the [blog](https://www.mindstick.com/articles/12705/myths-and-misconception-about-blog) hasnt been modified
- Or return the blog [view](https://yourviews.mindstick.com/view/84701/layoffs-in-google-india-2023-view) if it's been modified since If-Modified-Since [request](https://www.mindstick.com/blog/255/post-get-and-request-function-in-php) [header](https://www.mindstick.com/articles/336036/explain-about-html-header-body-and-footer-tags)

The [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) is when i want to return 304 status, how do i tell [spring mvc](https://www.mindstick.com/forum/543/spring-mvc-3-0-crud-application-using-annotation-and-jdbc-template) not to assume another view from the [null](https://www.mindstick.com/forum/33922/how-to-use-null-coalescing-operator-in-c-sharp) return, and start sending the [response](https://www.mindstick.com/forum/12719/how-to-make-response-write-display-special-character-like-lt-gt) with the status immediately ?

```
@RequestMapping(value={"/blogs/{blogId}"}, method=RequestMethod.GET)public String hello(final HttpServletRequest req, final HttpServletResponse resp, final Model model,        @PathVariable("blogId") final String blogId) {    if (isModified(req, blogId)) {        resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);        return null; // this doesnt stop spring mvc to assume a view name    }     populate(model, grabBlog(blogId));    return "blog";}
```

## Replies

### Reply by Anonymous User

From the HTTP perspective returning a view doesn't make sense at all. The [Spring](https://www.mindstick.com/forum/33718/spring-social-facebook-oauth-getting-not-all-data-with-api-v2-5) documentation covers that use case:

```
@RequestMappingpublic String myHandleMethod(WebRequest webRequest, Model model) {     long lastModified =// 1. application-specific calculation     if (request.checkNotModified(lastModified))
{        // 2. shortcut exit - no further processing necessary        return null;    }     // 3. or otherwise further request processing, actually preparing content    model.addAttribute(...);    return "myViewName";}
```


---

Original Source: https://www.mindstick.com/forum/12933/why-spring-mvc-optionally-returning-no-view-in-a-single-mapping

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
