Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is the best way to get started with struts?

 
Surendra Kashyap
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have done significant servlet/jsp based development work and have good understanding of "servlet container". However, I have not done "framework" such as "Struts" based web development. What would be best way to get started quickly? I am hoping to migrate traditional "web application" into "Struts" based application.

Thanks!

Surendra
 
Danilo Gurovich
author
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would recommend "Struts in Action". If you read the first few chapters in it and "get" what is happening, you should be able to begin developing quickly.

Make sure that you understand what MVC2 "architecture" is.

Struts will "help" you implement good MVC2 practices, but it won't prevent you from creating Struts Applications that are incorrectly written. To get around this type of pitfall, here are a few of my recommendations...

WRT the JSP side of your code, you'll need to understand JSP tags and taglibs. You'll also need to make sure that your business logic isn't in your View Layer (JSPs), but safely encapsulated in your server-side. Your JSP's should only have information and code in it that is specifically related to your view.

When you create Actions, make sure that there is little or no business logic in them. Basically, they should be used to pass information from the View to your Model for processing and back, with the only logic in these classes based upon where to direct the response. If you encapsulate your business logic in this layer, you risk duplication of code at least, and if you should decide to abandon Struts for something else, you could end up rewriting thousands of lines of code to more all that business logic.

As far as your back end goes, it should be completely encapsulated and "not care" about the view. You should think along the lines of your business layer operating from a command line, Swing Client, JSPs, or any other view layer. If it is dependent upon a View technology, then you probably need to do more work.

Once you are at this point, you can begin your migration. I'm going to discuss this using the struts tag library in its 1.1 form (Since I don't know what servlet container you're running or what Java/JSP you are using, this is a safe bet. If you want to upgrade to Struts 1.2x you're more than welcome to as long as you're familiar enough with what's going on). I would recommend implementing:

All your links should be changed to actions registered in the Struts-config.xml file.

Wherever any URL references or sources are in your code, you should use the <html:rewrite/> tag or an appropriate tag that will utilize url rewriting and encoding.

Create Form beans and join them to your actions.

Create validations

Tile and template your application -- you may want to use JSP tiles at first and then move to the tiles-definitions.xml file at a future date, depending upon the size and complexity of the application you are migrating.

Finally, add Struts' validations.

By the time you reach this point, your migration will be 80-90% complete and you'll have a pretty good idea as to how to proceed from this point.
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can start to use struts framework at JavaRanch Journal articles.

http://www.javaranch.com/newsletter/Mar2002/newslettermar2002.jsp#struts
http://www.javaranch.com/newsletter/Mar2003/newslettermar2003.jsp#struts

and Apache Struts
 
Bhavesh Ravjee
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I started learning struts with a book titled

Struts KICK START by James Turner and Kevin Bedell.
The book explains the framework quite well and provides a good grounding as well.

My suggestion is that once you have an understanding of the framework and its history(MVC) try and do as much examples as possible. I am still learning and improving day by day.

There is a good site out there that talks about struts and other more interesting stuff. Visit The Server Side.

Good Luck
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic