Powered by Blogger.

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'.

4.4. Value Objects/Data transfer object class.

>> Wednesday, June 17, 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.

How ActionServlet acting as a FrontController.in Struts

>> Sunday, June 14, 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.
Action Servlet acting as Front Controller_JavabynataraJ

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.

Struts Flow and Architecture

>> Saturday, June 6, 2009

Before going to know about Struts Flow and Architecture we get to know What is Struts Frame work? As per simple definition "Struts is an open Source framework, given by Apache Software Foundation, which is used develop MVC2 based web applications in java". Struts contains Validations, I18N(Internationalization and Exception handling features. Because of these three Struts became very popular.

Web.xml entries will be read by WebContainer of WebServer or Application Server software. Struts configuration file entry is will be read by ActionServlet.

WebContainer creates Actionservlet object where as FormBean class object, ActionClass object will be created by ActionServlet.
Struts Flow and Architecture_001

Related Posts Plugin for WordPress, Blogger...
© javabynataraj.blogspot.com from 2009 - 2022. All rights reserved.