wood burning stoves 2.0*
The moose likes Spring and the fly likes Integarting existing jsps and Servlets Web Application  with Spring 3.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Integarting existing jsps and Servlets Web Application  with Spring 3.0 " Watch "Integarting existing jsps and Servlets Web Application  with Spring 3.0 " New topic
Author

Integarting existing jsps and Servlets Web Application with Spring 3.0

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

We are using Servlets and JSps as our Front End , and we want to use Spring
In order to achive Application context in my web layer , using



Do i need to write this piece of code in each of my servlet .

Or i shall make a Filter and mention this code there ??

Please suggets . Thanks .


Save India From Corruption - Anna Hazare.
Won Cho
Greenhorn

Joined: Dec 22, 2010
Posts: 6
It's unfortunate that you're not taking advantage of Spring MVC or Spring Webflow.... but if you truly want to be on the route of "Servlets & JSP" then I would create a Abstract Class that your servlet extends. In that Abstract class, you'll have a method like Object getBean(String beanName). Of course, your abstract class will extend the httpservlet. Again, if you could have a choice to use any MVC framework...I strongly recommend that approach...
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Hi Won Cho , thanks for the suggestions , but

It's unfortunate that you're not taking advantage of Spring MVC or Spring Webflow.


I agree with you on this , but ours is a legacy Application (developed since 2004 ) , so we want to keep our Existing functionality working .

then I would create a Abstract Class that your servlet extends. In that Abstract class, you'll have a method like Object getBean(String beanName).


What advantage i get from this , i am thinking of writing a simple class (A factory class ) , which will be responsible to return the ApplicationContext using WebApplicationContextUtils.getWebApplicationContext(getServletContext());

What do you suggest ?? please advice . Thanks .
T. Huy Nguyen
Ranch Hand

Joined: Nov 02, 2010
Posts: 57
Ravi Kiran Va wrote:

then I would create a Abstract Class that your servlet extends. In that Abstract class, you'll have a method like Object getBean(String beanName).


What advantage i get from this , i am thinking of writing a simple class (A factory class ) , which will be responsible to return the ApplicationContext using WebApplicationContextUtils.getWebApplicationContext(getServletContext());

What do you suggest ?? please advice . Thanks .


Having both are good. With the Abstract servlet class and inherrited getBean method, you don't need to pass the ServletContext instance as argument. You can also use your factory class to serve more than just servlet, but also tags, filter...


My material for SCJP (2008), SCWCD (2010), SCBCD (2010). About me
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Having both are good. With the Abstract servlet class and inherrited getBean method, you don't need to pass the ServletContext instance as argument.

Agreed , and good approach also . Thanks .
Won Cho
Greenhorn

Joined: Dec 22, 2010
Posts: 6
As I said before, I'd still consider converting that into Spring MVC. All that servlet is doing is processing doget or dopost with httprequest and httpresponse. You can easily convert that into Spring MVC @Controller and @RequestMapping feature. I think once you convert 1 servlet, all the remaining would be just repeated process. It maybe worth your time to evaluate how much effort is needed to convert your servlets. My guess is less than 1 hour for the first one and probably 15~30 min for the rest.
Won Cho
Greenhorn

Joined: Dec 22, 2010
Posts: 6
There are many features for Spring MVC but just having automated testing for @Controller should be more than enough reason to change... I'm guessing that there is no automated testing for your servlets.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Integarting existing jsps and Servlets Web Application with Spring 3.0
 
Similar Threads
Spring in Web Application - How can I get the application context from a Java class
nonintrusive in spring
Dispatching a request
Spring DAO in a web application.
Allow Only include