Can We Avoid JSP's in Struts FrameWork
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Wednesday, November 28, 2001 01:32 PM

Hi,


Can We use Servlets to Paint Screen instead of JSP's in Struts Framework, if Yes What are its Disadvantages,Modifications needed etc...






Thanks
Renny Jose

Re: Can We Avoid JSP's in Struts FrameWork

Posted By:   Ted_Husted  
Posted On:   Wednesday, November 28, 2001 05:56 PM

The response object is passed to the Action perform method. You can use this to
write your own response to the client, in the usual way. The standard Struts "reload"
action does this to paint "OK" to screen after reloading the mappings.


For fancier pages, the best thing would be to have your servlet answer to it's own URI pattern. The Struts Action could then forward to that, the same as it does with JSPs.


Your serlvet can then look in the request context for the ActionForm, or whatever other objects you will use, and render the response from that. If your servlet just does what the HTML tag extensions do, then the rest of the framework will be none the wiser. And all they really do is populate the HTML control using the properties of an ActionForm found in the request context.


The other resources used by the tag extensions, like the mappings and messages, are available in application scope, so your servlet could use those too, if needed.


On an incoming request, the ActionServlet sets the values on the ActionForm bean via reflection. It doesn't now or care how the values got into the HTTP request. It's just looking for name=value pairs in the HTTP request that match the property names on the designated ActionForm.


The tag extensions know to look for the ActionForm in the request context, or instantiate one if it's missing. The latter part is so any default values can be given to the HTML controls. The tags also know how to look into the mappings to find out which ActionForm goes with which Action, but that's added value. You can always code that part by hand (and at one point, we did).


But so long as the names of the HTML controls match the ActionForm names, it doesn't matter who writes the HTML. HTTP is the great equalizer.


The JSPs are not tightly coupled with the framework, and anything they do could be done by another servlet. It is helpful, though, if your serlvet answers to its own URI pattern, as the JSP service does. Architecturally, this then makes it a drop-in replacement for JSPs.


I understand that there is a renewed interest on the Jakarta Velocity list about using their servlets with Struts. The strategies they use would probably work for you too.


HTH -Ted

About | Sitemap | Contact