How have best performance with jsp?
i'm with some dobuts:
1) how can i take best pratices to have best perfomance with my website in jsp ?
2) how i should use treat request.session.getAttribute() and request.attribute() ?
3) all the data between servlet and jsp should be in request.session.getAttribute ? Or in req开发者_StackOverflow中文版uest.getAttribute ?
i'm asking this cause, after a time of use, my tomcat stops, and i'm working with the same tomcat in another project and this never happens.
Best regards, Valter Henrique.
- Don't worry about jsp-performance, it's been proven and tested enough already.
- The session is valid for a user between many requests, the
request.getAttribute
is unique for every newHTTP
request made to your servlet. - Definately put all data you can into each request, meaning you have to use
request.getAttribute
.
If you have problems with your tomcat, I would recommend that you either post your stack-trace or hook up some monitoring tool (like your IDE debugger
or something like jconsole
).
Sessions can be useful too. A session typically contains information about logged in users and their preferences. For instance, it can be used to store a username or the theme to use should such thing be available.
Answers to your question are:
1) how can i take best pratices to have best perfomance with my website in jsp ?
Rather than coding servlets and jsp pages, you should be using a MVC framework. There are many java MVC frameworks like Spring, Struts, Wicket etc. They will help you in creating a better stable and maintainable application
2) how i should use treat request.session.getAttribute() and request.attribute() ?
Where to store the data is your design. If you need a attribute to be accessible in multiple requests, you will have to put it in the session. Whereas if you need a attribute only for 1 or 2 requests, you can do ahead with request. A better management is always provided by the frameworks I mentioned above.
3) all the data between servlet and jsp should be in request.session.getAttribute ? Or in request.getAttribute ?
Again, this depends on your application and how long you need the data you are trying to access.
精彩评论