>
Showing posts with label web application. Show all posts
Showing posts with label web application. Show all posts

Wednesday, January 16, 2013

Simple Application Use Servlet Part II Creating Baseline

Simple Application Use Servlet Part II
Creating Baseline

we will create the baseline for our simple application as we mentioned in last post, we just using one servlet for centralizing the request and response, as we know that our application not just, one request, but more. To meet this condition.
the step i chose:
  • we stay have one servlet
  • we have a lot url pattern servlet but stay one servlet and one name servlet
  • on the method doPost and doGet we instantiate only one object i will be named it CallingAction,
  • in callingAction we just call one method and pass parameter, userpath (request path/ url pattern)

    shabby note - simple application
    Baseline for Simple Application


why we create CallingAction, the idea is every time user do a request we provide by specific url pattern for each different request type, in the servlet class we can retrieve request path(url pattern name) that user hit. For handling the right method for the right url path. I chose step as describe bellow:

  • create labels for each name url pattern, method for the right request and also the class belong to the method
  • each specific url pattern has method, and has class belong to method, have the same labels name
  • based on labels that we created, by using java reflection for picking the right object and method for specific url pattern in CallingAction

For storing labels, I will use interface and grouping for each url path, method and the class belong to method, I will use interface too. The labels will have value as points bellow:
url path → url pattern name
method → method name
class →package_name.class_name

For storing data, I used Hashmap in singleton method. Every time user create user name or edited will be put in the hashmap .

Monday, January 14, 2013

Simple Application Use Servlet Part I

Simple Application Use Servlet Part I

Servlet is a java class can accept request from another java class, web client or other servlet, which can trigger the response, Sometime servlet is named HTTP Servlet because servlet were used combine with HTTP, but servlet itself not one of client server protocol specification.

We can make web application in java use servlet,  in web application there are many request-response process and make a lot servlet then make it our application is hard to maintain, web application requires a centralized access point for HTTP request handling to support the integration of system services like security, data validation etc, content retrieval, view management, and dispatching. When the user accesses the view directly without going through a centralized mechanism, few problems may occur :

  • Each view is required to provide its own system services often resulting in duplicate code.
  • View navigation is left to the views. This may result in shared code for view content and view navigation.
  • Distributed control is more difficult to maintain, since changes will often need to be made in numerous places.
Generally we write specific servlets for specific request handling. These servlets are responsible for data validation, error handling, invoking business services and finally forwarding the request to a specific JSP view to display the results to the user.

According that we better only have one Servlet (instead of having specific Servlet for each specific request) centralizing the handling of all the requests and delegating the functions like validation, invoking business services etc to a command or a helper component. The benefit that we have only one servlet are :
  • Avoid duplicating the control logic like security check, flow control etc.
  • Apply the common logic, which is shared by multiple requests in one controller.
  • Separate the system processing logic from the view processing logic.
  • Provides a controlled and centralized access point for your system.
As I describe about let’s gather requirement for making simple application using servlet.
Tool :
  • java JDK 1.6 or above because all servlet management such as naming, mapping or url pattern, initial params, because we can use annotation. I used Java JDK 1.7.
  • server I used tomcat 7
  • editor Eclipse Indigo
  • for storing data, I will use Collection class, map and stay in JVM in singleton state
Application process constraint:
  • user can log in to application and can edit his/ her profile after save the page will be directed to login form. For checking that the profile has been change user just login again and she/ he will see the profile and edit again.
  • If user not register yet, can go to page sign up after finish entry all data and submit user will be directed to login form and For checking that the profile has been change user just login again and she/ he will see the profile and edit again.