whats the correct way to pass connection keep-alive response header in spring mvc

I am making a java mvc web application. I saw some similar application written in nodejs..
while checking the header content through network tools i found that the application had following headers
which my application was not having :

Response Headers :
Date:Mon, 28 Sep 2015 12:02:18 GMT
X-Powered-By: Express

Remote Address:[::1]:8080
Request URL:http://localhost:8080/
Request Method:GET
Status Code:304 Not Modified

Request Headers
one extra param :

Open in new window

The two things i notice is has keep-alive in its header.
so i am wondering if i should also put keep-alive in my response.
I am thinking of just adding a line :
    response.addHeader("Connection", "keep-alive");
Is that the correct way ? will it work ?

The other thing i noticed is that its passing : Status Code:304 Not Modified
whereas by default my application is passing 200.
should i pass 304 ??

Rohit BajajAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
"keep-alive" connections aren't really the domain of the Spring layer. That is up to the underlying servlet/web container (ie. Tomcat, Glassfish, JBoss, etc) to determine if/when to send those headers. Also, because it is probably not JUST a case of setting that header for the functionality to work. I would recommend investigating this issue in the context of the servlet/web container that you are using.

Regarding status code 304, it is a lot more complicated than just sending a different code. You need to understand the reasoning behind those status codes. Notice the other headers that you posted above, in particular the "Etag" and "If-None-Match" headers. This is all to do with response caching, ie. if the response hasn't changed from one sent previously, don't resend it (hence the 304 Not Modified status). You should probably read up on ETag's and how they are supported in Spring.

Also, I wouldn't worry about either of these two issues (keep-alive and etags) at an early stage of a project (which I believe you are at at the moment). Get it working correctly first, and then worry about optimizations like these.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rohit BajajAuthor Commented:
yes thanks.. i will look up things.
Also actually the project which i am working on is already written in node.js .
what my task is to convert it to spring mvc. which i have done mostly.
So i am running both projects and matching if there are any differences in them.
Thats how i found that my web pages were not having those headers and the project was having.
So i have to bring both in line.
mccarlIT Business Systems Analyst / Software DeveloperCommented:
So i have to bring both in line.

Who said that you have to? I'm not saying that you don't but it may be that you don't have to worry. You are moving from node.js to Spring, so there are going to be differences anyway, and you may be getting hung up on these small things for no real end purpose.

Anyway, as I said, "keep-alive" is definitely 100% not something you should be catering for in your code. Look into whatever web/servlet container you are using.

And "ETag" support is not necessarily a simple add on where you can just set a few headers and your done. If you end up wanting/needing to add support for it, it will be something that will most likely affect a LOT of your project. Controllers, daos, models could all require changes to fully support caching and ETags.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Applications

From novice to tech pro — start learning today.