Tutorial for building J2EE Applications using JBOSS and ECLIPSE -8

【Unity】Gif图片播放插件(支持UI及模型纹理渲染两种模式) unity本身不支持GIF格式文件直接渲染, 因此一般的做法是通过加载图片,通过代码控制其循环播放、停止等,模拟动画效果,本文简单介绍一下某个现有开源工具,感谢开源作者。 阅读详情

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.




Add Business Method :

Before we start implementing our servlet, add one more business method to StoreAccess Bean called getAllItems() with the following signature:

public java.util.ArrayList getAllItems()

This method will return all the items in MyStore by invoking the finder method in ItemsLocalHome named findAll, as shown below (code snippet from StoreAccess bean):




Now let's start implementing the generated methods in the servlet.

Implement init method :

This method is responsible for initializing servlets, so it is invoked when the servlet is first created and is not called again for each user request.

We will cache the references for our StoreAccess Bean in this method, as all the client interfaces available are exposed in StoreAccess.

So, first create a context. Then get a reference to a StoreAccess object by looking up the StoreAccess bean via the JNDI API.

Add a variable storeAccessHome of type StoreAccessHome to store the reference obtained by narrowing the object.

Create helper methods for getting Context, Home and assigning the reference to storeAccessHome as shown below.


Note : We have to narrow this object because we are accessing a remote interface. If it was a local interface, we wouldn't need to narrow the object.

Implement methods doGet and doPost :

In order to implement these two methods we will create a helper method to provide the functionality for both of them. The request is delegated to this method where all processing of information takes place. Once this business logic processing is complete it dispatches the request to the appropriate view for display, ie. JSP pages.

Note : This approach is based on the Front Controller pattern, where the controller acts as a central point of contact for handling requests, delegating business processing, and coordinating with dispatcher components, whilst dispatchers are responsible for view management and navigation. This pattern suggests centralizing the handling of all requests in this way, but also allows for different handler methods to be used in processing different request types.

Add a method named procesRequest with the following signature:

protected void processRequest (HttpServletRequest request, HttpServletResponse response)
                                 throws ServletException, IOException 

Delegate request from doGet and doPost method to this method as shown below.


Now implement the processRequest() method.

This method is structured such that it will check for the parameter useraction within the request object. If the useraction parameter is empty then it will build a url for the login screen and generate a login screen page. If useraction has some value then it examines it. If it finds the request is to display items then it builds the url for that and generates a page displaying all the items. Finally, for errors a page is generated to display the error.

Add following attributes shown below, for building different urls.


Create a session object and get value from useraction parameter of request object as shown below in code snippet.


If useraction is empty, as it will be initially, then build the url for the login screen, and generate the login screen by invoking the method displayLoginScreen. Code snippet for displayLoginScreen is shown below.


This method calls displayLoginDataFields to generate the data fields for form submission as shown below.


Once this form is submitted, it checks to see whether validation is successful by invoking the method loginUser, which invokes the loginUser method in the StoreAccess Bean as shown below.


Once that is finished, as shown above in the processRequest method code snippet, it builds url's for displaying items and error. Code snippet for the method displayAllItems is shown below.


Code snippet for displayLoginErrorScreen shown below.


All these helper method are being used by the processRequest method, which is acting as a Controller and dispatches the request to the appropriate view, such as the login screen or display items screen.

Now our servlet is complete, as implementation of the rest of the methods is left as an exercise.

Deploy AccessController Servlet :

In order to deploy your servlet, go to LombozJ2EE view.

Select web module OnlineStore > right click > select Deploy module as shown below , make sure the server is running.


Deployment status appears on the console as shown below. If deployment is successful then test your servlet.




Test your Servlet :

Go to your browser and access the servlet using following URL, 'http://localhost:8080/OnlineStore/access'

where 'access' is the url mapping that was assigned while creating the servlet using the Servlet Creation Wizard, and OnlineStore is the web module,where this servlet resides.

The login screen will be displayed. Enter username as 'ANDY' and password as 'PASSWD'. The next screen will be list of items in MyStore as shown below.




We have successfully created a servlet, now let's access this catalogue via a JSP page.

Create JSP Page :

Go To Package Explorer > Expand Web Module node (OnlineStore) > right click and a menu will pop up.

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


Add file name showItems.jsp as shown below.


Press Next > Menu, the form Set JSP details will appear > Select Add.. under Beans section as shown below.

The menu for Select Beans will appear > Add ID as itemData, Scope as page and Class as ItemData.


Press Ok. Now selected JSP details can be seen after selecting various options as shown below.



Press Finish. A new file named showItems.jsp will be created under the web module OnlineStore as shown below.






Modify Method processRequest in Servlet AccessController :

Now, in order to display all items of MyStore from a JSP page, we have to modify the proccessRequest method in servlet AccessController.

Modify String ITEMS_SCREEN to "/showItems.jsp" as shown below.


Comment out the call to method displayAllItems in processRequest.

Add a Session attribute named itemsList with values of listItems.

Add a Request Dispatcher and pass buildUrl as an argument, which has the url for the showItems.jsp page.

Forward to that request dispatcher to draw the JSP page.

Code snippet of the modified processRequest method is shown below.



Add Html and JSP Tags :

First import the following packages: au.com.tusc.cmp.*, java.util.ArrayList and java.util.Iterator.

Now add the necessary HTML and JSP tags to access items of MyStore.

Get itemsList from our session attribute set in servlet AccessController.

Set itemData as a page attribute via pageContext.

Now display the attributes of itemData using JSP property access tags. Code snippet for the showItems page is shown below.


Note : This JSP Page is a view in the Front Controller Pattern discussed above.



Now the JSP page is done.

Go to OnlineStore (web module) node > right click > select Lomboz J2EE.. on pop up menu > Check All JSP Syntax.

See if there are any errors.

Go to OnlineStore node > right click > select Lomboz J2EE.. on pop up menu > Add WEB-INF/lib JARs to the Classpath as shown below.




Deploy Module OnlineStore :

In order to deploy, go to LombozJ2EE view.

Select web module OnlineStore > right click > select Deploy module, make sure the server is running.

Deployment status will be visible on the console. If deployment is successful then test your JSP page.

Test your JSP Page :

Go to your browser and access the servlet using the following web address, 'http://localhost:8080/OnlineStore/access'

where 'access' is the url mapping that was assigned whilst creating the servlet in the Servlet Creation Wizard, and OnlineStore is the web module where the servlet AccessController resides.

The login screen will be displayed. Enter username as 'ANDY' and password as 'PASSWD'. The next screen will be the list of items in MyStore as shown below.




You have successfully created a JSP page using all the J2EE components, and they have been created and deployed successfully. Congratulations!

48、住宅抵押贷款支持证券的定价、风险评估与结构化设计 本文深入探讨了住宅抵押贷款支持证券(RMBS)的定价、风险评估与结构化设计。内容涵盖提高定价准确性的方差缩减方法,如准蒙特卡罗序列的应用;分析RMBS面临的利率风险、信用风险和模型风险,并提出相应的度量与应对策略;介绍利用动态规划优化CMO分层结构以最大化发行利润的方法。同时总结了RMBS的基本类型、定价流程及市场发展趋势,为投资者和发行人提供全面的决策支持。 阅读详情

相关推荐

保姆级教程:在DolphinScheduler 3.x中配置Apache SeaTunnel任务(Flink/Spark双引擎)

本文提供了一份详细的教程,指导如何在DolphinScheduler 3.x中配置Apache SeaTunnel任务,支持Flink和Spark双引擎。从环境准备、脚本选择到配置文件编写和任务调度优化,涵盖了所有关键步骤和常见问题解决方案,帮助用户高效集成SeaTunnel到海豚调度系统中。

weixin_42524945的博客 201

Tutorial for building J2EE Applications using JBOSS and ECLIPSE (8)

Chapter 8. Creating Web ClientsThis 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 a

Zero'Coffee 1127

tanner2019安装教程

tanner2019安装教程 tanner安装包 软件由老师提供,但由于老师给的方法不知怎么回事无法使用就自己找了一些方法,本教程仅提供参考 链接:https://pan.baidu.com/s/1A2O6JuEF8YFbe8bPnD3J6w 提取码:ysif 复制这段内容后打开百度网盘手机App,操作更方便哦 安装过程 1.选择TannerTools_v2019.2-Win64.exe,进行安装。 2.选择安装产品 3.选择目标路径 4.确认安装 5.安装成功,退出。 获取许可过程 1.打开key压缩

weixin_47730560的博客 1万+

Tutorial for building J2EE Applications using JBOSS and ECLIPSE -2

Chapter 2. Overview Of J2EE Technology and ConceptsThe Java 2 Enterprise Edition (J2EE) is a multitiered architecture for implementing enterprise-class applications and web based applications. T

阿龙专栏 2238

QTableView实现表格加载百万条数据

本文介绍用QTableView实现加载100万条数据显示到表格。 1.创建工程 用Qt Creator创建Qt Widgets Application项目,基类选择QWidget,创建好了,如图: 2.添加QTableView控件 在widget.ui中添加QTableView控件,和QPushButton,采用栅格布局,如图: 3.添加函数 头文件 QT_BEGIN_NAMESPACE namespace Ui { class Widget; } QT_END_NAMESPACE class Wid

丁爸的博客 8273

openEuler 20.03 LTS面向RK3399移植系列(3)—openEuler 20.03 LTS面向Firefly RK3399的第一个版本(Linux kernel 4.4)

任务动机:完成openEuler面向RK3399开发板的移植。 任务描述:按照固件烧写准备,固件获取,固件打包和烧写的步骤实现openEuler面向RK3399开发板的移植,整理过程和相关命令记录到文档。 1. 制作openEuler的rootfs.img 1.1 开发环境 树莓派--openEuler系统 openEuler 20.03 LTS 的内测版本镜像,下载。 1.2 具体操作 1.2.1 ssh远程连接树莓派 确定树莓派IP ssh连接 1.2.2 制作rootfs.img

火种源码的机器人技术专栏 2378

Tutorial for building J2EE Applications using JBOSS and ECLIPSE Chapter 3

在阅读这一章的时候,基本没有什么障碍,但是有一个地方文章是写错了。 在Create DAO Interface  那一节中“Go to src > add package named au.com.tusc.dao > Add a class StoreAcessDAOImpl in that package”红色字体错了,应该是StoreAccessDAOImpl。 还有就是因为使用不同版本的j

中国 IT 应用/ Adapting information technology in china 1206

CIC-IDS-2018数据集高效预处理实战:从数据清洗到特征整合

本文详细介绍了CIC-IDS-2018数据集的高效预处理方法,从数据清洗到特征整合的全流程实战。通过内存优化、异常值处理和特征工程等技巧,帮助网络安全研究人员快速处理大规模网络流量数据,提升机器学习模型的训练效率和准确率。特别针对特征数据的预处理提供了实用代码示例和优化建议。

weixin_29274969的博客 507

Tutorial for building J2EE Applications using JBOSS and ECLIPSE -5

Chapter 5. Creating a BMP Entity BeanThis chapter describes how to create a Bean Managed Persistence (BMP) EJB component. We will create two BMP beans, Customer and Manager, as shown below. The

阿龙专栏 1733

备战2025数学建模国赛(算法46):多目标优化

本篇博客将深入浅出地介绍多目标优化的核心概念、主流算法,并重点结合一个数学建模竞赛的经典案例,提供完整的Python代码实现,助你在未来的竞赛中游刃有余。它通过寻找帕累托最优解集,完美地诠释了“鱼与熊掌不可兼得”的权衡思想,为最终决策提供科学依据。这些问题都包含多个相互冲突的目标,传统的单目标优化方法(如梯度下降、单纯形法)对此无能为力,因为它们无法同时优化多个目标。在数学建模竞赛中,我们面临的绝大多数问题都不是单一的“最好”,而是充满权衡与妥协的“最优”。记住,成功的建模不仅在于解出问题,更在于清晰地。

YOLO 291

ICC2:平行打孔create_pg_stapling_vias

power rail(follow pin)不总是metal1一成不变的,当需要使用metal2做power rail,而standard cell的pg pin仍然是metal1时就需要平行打孔,从metal2到metal1。 以往都是用create_pg_vias -allow_parallel_objects来做,但这样有两个弊端,一是需要抓出所有的via12(包括standard cell内部的和出pin绕线产生的),添加routing blockage,防止create pg via的时候产生d

m0_61544122的博客 2264

Tutorial for building J2EE Applications using JBOSS and ECLIPSE

Table of ContentsTutorial.PrefaceAbout the AuthorsAcknowledgmentsDisclaimerIntroductionPrerequisites for this tutorialTools re

阿龙专栏 4632

让 PyCharm 代码“发光”:高亮插件与特效全攻略

PyCharm 作为一款强大的 Python IDE,支持多种插件让代码“发光”——无论是动态输入特效、彩虹括号,还是霓虹主题,都能让你的代码脱颖而出!进入 File → Settings → Editor → Color Scheme → Rainbow Brackets。进入 File → Settings → Appearance & Behavior → Material Theme。进入 File → Settings → Editor → Color Scheme → General。

qq_43580271的博客 3854

Tutorial for building J2EE Applications using JBOSS and ECLIPSE -7

Chapter 7. Creating a Message Driven BeanThis chapter covers how to create a Message Driven Bean (MDB) EJB component. We will create two MDB beans, DeliverItems and RequestItems as shown below.

阿龙专栏 1499

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

Tutorial for building J2EE Applications using JBOSS and ECLIPSE -1

Chapter 1Configuration of ECLIPSE to use JBOSS and LOMBOZInstall Eclipse. First of all we have to set up Eclipse Integrated Development Environment (IDE) with JBOSS as our application server.

阿龙专栏 1951

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

Tutorial for building J2EE Applications using JBOSS and ECLIPSE Chapter 2 part 2

J2EE中的分布式应用(Distributed Architecture in J2EE ) 刚好在huihoo论坛看了一篇文章说到如何提高jboss的RMI/IIOP的效率问题,“有个应用是客户端swing+j2ee SERVER ,跑在内网没问题的。现在有个客户,很多分支机构,都是通过adsl(2m带宽)连到总部。j2ee服务器放在总部,感觉特别慢”,这个问题我现在还找不到解决的方法。刚好又看

中国 IT 应用/ Adapting information technology in china 1931

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

Tutorial for building J2EE Applications using JBOSS and ECLIPSE Chapter 1

现在才补回chapter的阅读经历是因为觉得有一个地方的确要提一下。 在安装配置的时候,资料上说明是使用jboss-3.2.1和lomboz.21_02,我决定使用jboss 3.2.5和lomboz 213。虽然对jboss新增的版本特性不清楚,但是我想既然能升级,已经是解决了已经遗留的问题。但是我在配置的时候却给我增添了麻烦。lobmboz 213并没有对jboss 3.2.5有相应的配置文件

中国 IT 应用/ Adapting information technology in china 1266

Tutorial for building J2EE Applications using JBOSS and ECLIPSE(1)

Chapter 1Configuration of ECLIPSE to use JBOSS and LOMBOZInstall Eclipse. First of all we have to set up Eclipse Integrated Development Environment (IDE) with JBOSS as our application server.So go to

Zero'Coffee 1369

Tutorial for building J2EE Applications using JBOSS and ECLIPSE(3)

Chapter 3. Creating a Stateless Session BeanThis chapter covers how to create a stateless session EJB component. This bean will be responsible for authenticating the user by communicating with the dat

Zero'Coffee 1136

Tutorial for building J2EE Applications using JBOSS and ECLIPSE -3

Chapter 3. Creating a Stateless Session BeanThis chapter covers how to create a stateless session EJB component. This bean will be responsible for authenticating the user by communicating with t

阿龙专栏 1621

Tutorial for building J2EE Applications using JBOSS and ECLIPSE(4)

Chapter 4. Creating a Stateful Session BeanThis chapter covers how to create a stateful session EJB component. Unlike stateless beans, stateful bean instances are associated with a particular client s

Zero'Coffee 1143

Tutorial for building J2EE Applications using JBOSS and ECLIPSE Chapter 2 part 1

All J2EE components are written in the Java programming language 这句话开宗明义的说明了J2EE只能用java来开发,我听说有一些开源爱好者已经可以做到用.net来做,然后通过一些转换器来工作,我也不是很了解这个东西。不过就我而言,要开发.net的就用微软的东西,不要想太多,毕竟那个才是专业的。开发j2ee还是用java算了。 T

中国 IT 应用/ Adapting information technology in china 1403

Tutorial for building J2EE Applications using JBOSS and ECLIPSE -4

Chapter 4. Creating a Stateful Session BeanThis chapter covers how to create a stateful session EJB component. Unlike stateless beans, stateful bean instances are associated with a particular cl

阿龙专栏 1440
上一篇: Tutorial for building J2EE Applications using JBOSS and ECLIPSE -7
下一篇: Tutorial for building J2EE Applications using JBOSS and ECLIPSE-9
jhlcss
博客等级 码龄25年 1粉丝 23原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值