4.5.Struts configuration file

>> Sunday, June 21, 2009

The struts-config.xml  file is heart of the struts-application containing FormBean classes,Action classes configuration , the entries in this xml file will be read by framework software.
  • Reading entries of web.xml is the responsibility of under laying web server or application server, application servers are using sax api, sax parser to read and process web.xml file.
  • Struts framework software uses SAX parser, SAX api to read and process struts configuration file.
  • Any "filename.xml" can become struts configuration file but it must be specified as input value to ActionServlet by using its init parameter 'config'.

Read more...

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Google Bookmark Yahoo ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl

4.4. Value Objects/Data transfer object class.

>> Tuesday, June 16, 2009

In order to send multiple values from one layer to another layer, it is recommended to combine multiple values into single object and send that object ot destination layer. It is not recommended to send multiple values between two layers foe multiple number of times. The class whose object combines multiple values into single object is called ValueObject class or DataTransferOject class.

  • The implementation of this design pattern reduces round trips between two layers and it also makes easy to receive values only for one time in the destination layer.
  • In struts application FormBean class acts as ValueObject class or DataTransgerObject class. Because multiple values given by form(data means form data) or stored into single object called FormBean class object and this FormBean class object is implicitly visible in the action class execute(). The business logic of execute() uses form data as input values by reading them form FormBean class object.
  • In struts applications Form data of the view layer is visible Action class of modellayer. In the form of FormBean class object.

Read more...

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Google Bookmark Yahoo ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl

4.3. How ActionServlet acting as a FrontController.

>> Saturday, June 13, 2009

A special web resource of web application that traps request comming to other web application to execute common and global pre request processing logic by username and password is called "Front Controller".

Servlet acting as a Front-controller , then it is called Front-controller servlet. If JSP is acting as Front-controller then it is called Front-controller JSP.
To make ordinary Servlet/Jsp as front controller you must be configured having directory match URL-pattern or extension match URL-pattern. In Struts based applications ActionServlet is takes as Front Controller.Due to this we can make Action class response going to browser directly with out having any trapping of response from ActionServlet. Since Action Servlet is controller of Struts based MVC application, it is recommended to write such logic in Action class based on which Action servlet traps the response of Action class.

  • Front controller web resource is responsible to trap request comming to other web resources of web application but it is not responsible to trap response generated by other web resources of web applicaion.
Q: Why ActionServlet is given as FrontController Servlet of Struts based web application..?

A: The class(not servlet,jsp) of web application can't take http request directly. Action classes of struts application are ordinary java classes . But they can't take http request given by browser directory. To overcome this problem front controller action Servlet traps all the requests cumming to struts based web application, and passes the request to appropriate action classes this is possible only when action servlet is front controller .

If the form generated request to struts based web-application always targets to executes business logic of Action class. Since Action class can't take this http request directly. Traping thes request and passing this request to Action class is the responsibility of Front Controller Actionservlet.
  • Even though ActionServlet is built-in-servelt configure in that serlet in web.xml as front controller eigther by having directory match or extension match url-pattern is the responsibility of programmer.
  • A Servlet becomes front controller when it is having extension match or directory match url-pattern and pre reqesition processing logic.
  • Action servlet can be configure by having directory match or extension match url-pattern one is recommended extension match url-pattern .That to" *. do" is recommended.
ActionServlet configuration code in web.xml

  • In the above code ActionServlet is configured as frontcontroller by having extension match url-pattern '*.do'.
  • In the above code "config" is the fixed unique parameter name expecting name & location of struts configuration file(technical input value). A .xml can become struts configuratio file. But this file name is location must be informed as to action servlet as the value of unique parameter "config" as shown above.
  • To pass non technical input values to servlet from browser as reduced use request parameter. (query string), form data. To pass technical value to servlet from server side useing web.xml.They take the support of unique parameters of context parameters.
  • To eqalize response time of all the requests comming to servlets make webcontainer creating object of servlet eigther during server startup or when web application is deployed. For this enable servlet.
  • To activate struts framework software before the first request it is recommended to enable.
Note: When multiple servlets of web application are enabled with in which order these servlets object should be created during server start-up will be decided based on their load-on-start-up priority values. High value indicates low priority,low value indicates high priority, zero indicates least priority.

Read more...

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Google Bookmark Yahoo ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl

4.2. Design Patterns

>> Monday, June 8, 2009

Design patterns are set of rules which come as best solutions for reoccurring problems of application development.
Design patterns are the best practices to use software technologies in application development.
Design Patterns:

1.Singleton java class:
Java class that allows to create only one object per JVM is called Singleton java class.
  • Instead of creating multiple objects of a java class having same data. It is recommended to create one object per JVM and using for multiple number of times. This process reduces memory wastage.
  • In MVC architecture based application there must be only one servlet class object acting as Controller. So ActionServlet which is built in ControllerServlet of struts based web applications is given as Singleton java class.
  • Every servlet is a single instance multiple threads components.That means when multiple requests are given to servlet class only one object of Servlet class will be created and multiple threads will be started on that object representing multiple requests.
Q: Servlet(ActionServlet) is a single instance, multiple threads component. Then what is the need of designing ActionServlet as Singleton Java class.?

A: ActionServlet is a built in servlet given by struts Framework spftware as singleton java class.

  • Some web containers of webservers/application servers are violating servlet api-specification principles by creating multiple objects for servlet class in some special situations.
Ex: If a servlet deployed in weblogic server gets more than 300 requests at a time or simultaneously, the web container of weblogic creates second object of servlet class. This i simply violation of servlet specification rule called that servlet is a single instance multiple thread component.

When struts application is deployed in these special servers in order to see only one object of ActionServlet is given as singleton java class.

A Servlet is identified through its url-pattern. We can use one of the three approaches to provide url-pattern for a Servlet.
 

1.Exact match:
other matchings:

<url-pattern>/first</url-pattern>
<url-pattern>/first.xyz</url-pattern>

Example url : (valid)
  • http://localhost:8080/wa1/first/xyz
Example url : (invalid)
  • http://localhost:8080/wa1/xyz/first
  • http://localhost:8080/wa1/xyz
  • http://localhost:8080/wa1/first
  • http://localhost:8080/wa1/abc
  • http://localhost:8080/wa1/first/xyz/abc
Note: In Exact match url-pattern * (star) symbol will not be there.

2.Direct match:
  • Direct match url pattern ends with * symbol.
  • url-pattern is to provide the secrecy to servlet by hiding their names.
Example urls(valid):

http://localhost:8080/wa1/x/y/abc
http://localhost:8080/wa1/x/y/z/abc
http://localhost:8080/wa1/x/y/
http://localhost:8080/x/y/xyz/a/b/abc
Example urls(invalid):

http://localhost:8080/wa1/y/x
http://localhost:8080/wa1/a/b/x/y/abc

3.Extension match:
Extension match url-pattern starts with '*' symbol.

Example urls (valid) :

http://localhost:8080/wa1/x/y/z.cpp
http://localhost:8080/wa1/x/y.cpp
http://localhost:8080/wa1/.cpp

Example urls (invalid) :

http://localhost:8080/wa1/a/b/c.cpp/x/y
http://localhost:8080/wa1/x/c.abc

Any extension will be given but it has to match the given URL pattern extension.

We can't frame URL-pattern by mixing up extension match and directly match.Because the underlying web server does not recognize this kind of URL-pattern . Because it is against servlet specification.

Read more...

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Google Bookmark Yahoo ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl

4.1.Struts Flow and Architecture.

>> Saturday, June 6, 2009

Struts Flow / Struts Architecture

Web.xml entries will be read by web container of webserver or application server software. Struts configuration file entry is will be read by action servlet.

web container creates Actionservlet object where as FormBean class object, Action class object will be created by ActionServlet.

  •  In the above diagram Business Logic is kept in Action class ..so it is called as "MODEL".
  •  Execute method in Action class is fixed method.Earlier this method is given as perform(-,-,-,-)method .
  • Perform(-,-,-,-) is the deprecated method of execute(-,-,-,-) method form Struts1.1 version onwards.
  •  Struts 1.0-> perform(-,-,-,-) method
  • Struts 1.2,1.3 -> perform(-,-,-,-) (deprecated) , execute(-,-,-,-).

With respect to the above diagram:

1. End user submits the request from JSP form(register.jsp) to struts based web application.
2. Based on the configuration done in web.xml ActionServlet traps the request and takes the result.
3. ActionServlet uses struts configuration file entries to decide FormBean, Action class to be utilized to process the request.
4. ActionServlet creates or locates FormBean class object and writes received from data to FormBean class object.
5. ActionServlet creates or locates Action class object.
6. ActionServlet calls execute(-,-,-,-)method of Action class, Business logic of execute(-,-,-,-) mehtod executes and result will be generated.
7. ActionServlet takes the control from Action class.
8. ActionServlet uses Action forward configurations of struts configuration file to decide result JSP(result.jsp) page of Action class.
9. ActionServlet forwards the control to resultpage called result.jsp.
10. Presentation logic of result page executes(result.jsp) to formatt result goes to browser as response.
11. This formatted result goes to browser as response.

//Reading struts Configuration file.

Reading request data, creating or locating FormBean, Action class Objects are the responsibilities of ActionServlet.

X.jsp ----> Form
XForm ---> FormBean class
XAction ---> Action class
Ex:

register.jsp ---> Form
Register form ---> FormBean
Register Action ---> Action class

naming conventions are very useful to make sources of the application selfdescriptive.

//Any .xml can act as structs configuration file. there is no default struts configuration file name.
  • If Business Logic is kept in Action class then it is called MODEL.
  • If Action class contains logic to interact with other model components like EJB, SPRING WITH HIBERNATE applications then Action class is called helper to controller servlet called Action servlet.
Q: Which roll you prefer for Action class.
A: We always to recommended not to place business logic in action class.
Reasons are:
  • Business logic becomes specific to one web application(Business logic is not reusable).
  • Allows only Http clients to access the business logic. AWT application, SWING applications,Standalone Java applications are called "nonHttp applicaions".
  • Middleware services(Additional services) must be implemented manually .To overcome all these problems keep business logic in EJB components are spring with Hibernate applications and make a Action class helper to controller to communicate with these model components.
Note: In most of the projects action class will be taken as helper to controller.

Read more...

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Google Bookmark Yahoo ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl

Related Posts Plugin for WordPress, Blogger...

Random Posts

JavabynataraJ - Find me on Bloggers.com Find me on blorner.com Technology Blogs JavabynataraJ Backlinks Blogarama - The Blog Directory

  © Blogger template Webnolia by Ourblogtemplates.com 2009

Back to TOP