您的位置:首页 >> 编程开发 >> Java >> Java基础 >> Eclipse >> 正文
Eclipse RSS
 

TutorialforbuildingJ2EEApplicationsusingJBOSSandECLIPSE-8

http://www.rdxx.com 06年12月09日 04:26 互联网 我要投稿

关键词: Tutorial , san , J2EE , Eclipse , JB , ATI , UI , ONS , IP

Chapter 8.

Creating Web Clients

This chapter describes how to create web clients in the Client Tier/Presentation Tier to access or otherwise communicate with the Business Tier. Servlets and JSP pages are the two examples of web clients which will be created. In a typical Model View Controller Pattern, the Servlet acts as the Controller whilst JSP pages act as the View (the Model being the data, of course).




Tasks :

  1. Create a Servlet named AccessController under the package au.com.tusc.servlet.

  2. Add a business method to StoreAccess Bean named getAllItems() with the following signature

    public java.util.ArrayList getAllItems()

  3. Implement the init method.

  4. Implement doGet and doPost methods.

  5. Add a method processRequest with the following signature

    protected void processRequest (HttpServletRequest request,HttpServletResponseresponse)

    throwsServletException, IOException

  6. Implement the processRequest method.

  7. Deploy the AccessController Servlet.

  8. Test the AccessContoller Servlet.

  9. Create a JSP Page named showItems.

  10. Modify the method processRequest in Servlet AccessController.

  11. Add HTML and JSP tags to display a list of all items in MyStore.

  12. Deploy the module OnlineStore.

  13. Test the showItems.jsp page.


Create AccessController Servlet :


Go To Package Explorer > Expand Mystore (project) node > select src, right click and a menu will pop up.

On the pop up menu > New > Lomboz Servlet Wizard as shown below.




Enter the package name au.com.tusc.servlet, with servlet name AccessController and select four methods to be implemented in the servlet as shown.




Press Next. A new screen will appear as shown below. Add Web Module (Browse.. web module and it will show list of web modules in this project), in this case it is OnlineStore, so select that. Enter the Servlet name as access, and Mapping URL as ' /access/* '.


Press Finish.

This will create a package named au.com.tusc.servlet under src and AccessController within that package as shown below.


As can be seen from the figure above the four methods we selected in the wizard are created, and only their implementation is required.

Apart from this, some descriptors are generated in web.xml, under Web-Module OnlineStore/WEB-INF as shown below:


These tags are generated by the Servlet Creation Wizard, where <url-pattern> tag specifies the path name by which the servlet will to be accessed. In this case it will be http://localhost:8080/OnlineStore/access. (N.B. - It's not necessary to have the same <servlet-name> and <url-pattern>.)

Web.xml contains all the deployment descriptors required for deployment of servlets.

Lomboz creates two pages when you create your web module, index.jsp and error.jsp.

Before we go further and start getting our hands dirty with servlets, let's have a look at what directories and files are generated by Lomboz under Web Modules, in this case OnlineStore, as shown below.


Files of interest include web.xml, where all the deployment descriptors will be placed (as discussed above), and targets.xml, which contains information about the server in which it will be deployed (in this case JBOSS). See the code snippet below from targets.xml.

9 7 3 1 2 3 4 4 8 :


 
 
标签: Tutorial , san , J2EE , Eclipse , JB , ATI , UI , ONS , IP 打印本文
 
 
  热点搜索
 
 
 



Valid XHTML 1.0 Transitional
Copyright ©2005 - 2008 Rdxx.Com,All Rights Reserved
收藏本页
收藏本站