已阅读5页,还剩19页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
JavaEE 平台技术实 验 指 导 手 册授课教师: 程保中实验指导教师: 谢锦教学对象: 二年级本科生开课时间: 秋季学期北京邮电大学软件学院2010年9月Java EE平台技术实验指导书程保中 谢锦一、实验一:Java EE编程(基础练习)1、 实验目的学生通过使用Java EE 平台进行程序的开发,掌握支持 Java EE 开发的通用IDE Netbeans,练习Java WEB 工程的创建、向工程中添加 JSF 网页组件、向工程中添加Servlet组件、熟悉 web.xml 的结构及使用。2、 实验内容(详细内容见附件一)3、 实验环境a) Windows XP 或 Windows 7b) NetBean 6.9c) MySQL 5.14、 实验要求1) 独立完成实验内容要求(注:第二次上机才是以小组形式完成)2) 熟练使用Netbeans 进行Web 项目的创建,Web 组件的添加和配置。Web 项目的部署和运行。3) 需要上交Netbeans Web项目文件 (Zip 文件形式)4) 需要打印实验报告上交(标准格式见附件二)5、 实验步骤1) 启动Netbeans。2)建立project。3)向 project 中添加 Web 组件,编辑修订 web 组件4)生成、部署并运行web 项目,验证结果是否正确。5)如果报错或告警,做必要修改,重复3)5)步骤直到没有错误和告警。附件一:Project #1 Web Application StructureSoftware NeededBefore you begin, you need to install the following software on your computer.1. Java Standard Development Kit (JDK) version 6.0o If you already have installed JDK 6.0, you can skip this. 2. NetBeans IDE 6.9 o When you install NetBeans IDE, it will ask you which JDK you want to use. Lab Exercises Exercise 1: Create a new Web application called MyFirstWebApp Exercise 2: Look under the hood of the MyFirstWebApp Homework Exercise Exercise 1: Create a new Web Application In this exercise, you are going to create a simplest possible Web application that contains a single index.xhtml initially. You will then add a new Servlet and a new JSF file to the application.1. Create a new NetBeans project 2. Build and run the project 3. Modify the index.xhtml of the application 4. Add a Servlet to the application 5. Add a new JSF to the application (1.1) Create a new NetBeans project0. Start NetBeans IDE if you have not done so yet. 1. Select File-New Project. The New Project dialog box appears.2. Under Choose Project pane, select Web under Categories and Web Application under Projects (Figure-1). Click Next3. Under Name and Location pane, for the Project Name field, type in MyFirstWebApp as project name (Figure-2). Click Next (Figure-3).Figure-1 Create a New Web Applicatoin ProjectFigure-2 Create MyFirstWebApp projectFigure-3 Create MyFirstWebApp project3. Click Next, select Java Server Faces (Figure-4), Click Finish.Figure-4 Select Java Server Faces Framework4. Observe that MyFirstWebApp project node appears with the IDE generated index.xhtml file displayed in the source editor. (Figure-5)Figure-5 Create MyFirstWebApp project(1.2) Build and run the projectAt this point, you have a useless but fully complete Web application which contains a single JSF file, index.xhtml. You are going to build and run the application.1. Right click MyFirstWebApp project node and select Run. (Figure-6 below)2. The IDE then compiles any Java source files, and then deploys over the deployment platform - GlassFish V3 in this example (Figure-7). It also displays the browser (Figure-8)3. Observe that a browser is displayed accessing the application. (Figure-8)Figure-6 Run the ProjectFigure-7 Result of running the projectFigure-8 Accessing the application from a browser(1.3) Modify the index.xhtml of the applicationIn this step, you are going to modify the index.xhtml of the application.1. Double click index.xhtml file under MyFirstWebApp-Web Pages as shown in code below. The code fragments that need to be modified are highlighted in bold and red-colored font This is my first Web application This is my first Web application 2. Right click MyFirstWebApp project node and select Run3. Observe that a browser is displayed with your change. (Figure-9 below)Figure-9 Result of the running the application(1.4) Add a Servlet to the application1. Right click MyFirstWebApp project node and select New-Servlet. (Figure-10 below) The New Servlet dialog box appears. Click Next (Figure-11)Figure-10 Create a new servlet Figure-11 Create a new servlet2. For Class Name field, type in MyOwnServlet.3. For Package field, type in myownpackage. Click Next. (Figire-12 below)Figure-12 Create a new servlet4. Click Next and Select “将信息填写大部署描述符(web.xml). (Figure-13 below) Figure-12 Create a new servlet5. Click Finish of the Configure Servlet Deployment pane (Figure-13)Figure-13 index.html and MyOwnServlet.java6. Observe now that you have one JSF file, index.xhtml, and one servlet, MyOwnServlet.java in this application. (Figure-13). 7. Double click MyOwnServlet.java file under 源包-MyOwnPackage-Web Pages as shown in code below. The code fragments that need to be modified are highlighted in red-colored font。 protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException response.setContentType(text/html;charset=UTF-8); PrintWriter out = response.getWriter(); try out.println(); out.println(); out.println(Servlet MyOwnServlet); out.println(); out.println(); out.println(Servlet MyOwnServlet at + request.getContextPath () + ); out.println(); out.println(); finally out.close(); 。8. Right click MyOwnServlet.java project node and select 运行文件,Observe that a browser is displayed with your change. Pay attention to the URL used in the browser (Figure-14).Figure-14 Run the Servelet(1.5) Add a new JSF called MyOwnJSF.xhtml to the application1. Right click MyFirstWebApp project node and select 新建-JSF页. (Figure-15 below)Figure-15 Add a JSF Page to the Project2. For the JSF 文件名 field, type in MyOwnJSF. (Figure 16 below),Click 完成。Figure-16 Fill in JSF Page File Name3. Observe that MyOwnJSF is added to the project (Figure 17)Figure-17 Add a JSF Page to the Project4. Right click MyFirstWebApp project node and select Run. 5. Observe that the browser is refreshed. In the subsequent exercise, you are going to modify and access MyOwnJSF.xhtmlSummaryIn this exercise, you have built and run a simplest possible Web application that contains a single index.xhtml page first and then add a new JSF page and a new servletExercise 2: Look under the hood of the MyFirstWebApp applicationIn this exercise, you are going to examine the things under the hood such as web.xml.1. Examine the Web application project structure in Files view2. Examine WAR file directory structure3. Examine the web.xml file 4. Modify web.xml to use MyOwnJSF.xhtml as a welcome page5. Access MyOwnServlet 6. Example deployment platform(2.1) Examine the Web application project structure in Files viewA Web application is made of JSF files, Servlets, and library files. The MyFirstWebApp application has two JSF files, index.xhtml and MyOwnJSF.xhtml, a single servlet, MyOwnServlet.java, and default library files. You can add new JSF files, new Servlets, and new library files to the application as you did in Exercise 1.Under NetBeans, you work with your project mostly under Projects view but you can also see it from Files view. In this step, you are going to see the Files view of the MyFirstWebApp application. A Files view of a project displays directories and files of the project in your local file system.1. Select Files tab window. You should see the Files view of the MyFirstWebApp project.2. Expand src and expand java. You should see all the Java files.3. Expand web. You should see all JSF files (and HTML files if you have them). (Figure 18 below)Figure-18 File View(2.2) Examine the WAR file structureA WAR is a zip file that contains all the pieces that are necessary for deploying the application over a deployment platform such as Tomcat or GlassFish. In this step, you are going to see internal structure of the WAR file. The internal structure of the WAR file is constructed from the contents of the web directory under build directory. From NetBeans 6.9, if you Run the project, the WAR file is not created as a default. You will have to Build project in order to see the WAR file under dist directory.0. Right click the MyFirstWebApp project node and select Build(生成). This is to create WAR file for the sake of this exercise.Figure-19 Generate WAR File1. Under Files view of the project, expand dist. You should see MyFirstWebApp.war file.2. Expand MyFirstWebApp.war. You should see WEB-INF directory, MyOwnJSF.xhtml and index.xhtml in the root directory.3. Expand WEB-INF-classes. You should see myownpackage directory which then contains MyOwnServlet.class. (Figure 20 below)Figure-20 File View(2.3) Examine the web.xml1. Click Projects tab window.2. Double click web.xml under WEB-INF directory. Click XML to see the file in the XML file format.Figure-21 web.xml(2.4) Modify web.xml to use MyOwnJSF.xhtml as a default JSF file to get displayed1. Modify MyOwnJSF.xhtml file as shown below. The code fragments that need to be modified are highlighted in bold and red-colored font. My Own JSF Page My Own JSF Page 2. Modify the web.xml as shown below. The code fragments that need to be modified are highlighted in bold and red-colored font.。 Faces Servlet javax.faces.webapp.FacesServlet 1 MyOwnServlet MyOwnPackage.MyOwnServlet Faces Servlet /faces/* MyOwnServlet /MyOwnServlet 30 faces/MyOwnJSF.xhtml 3. Right click MyFirstWebApp project node and select Run. You should see MyOwnJSF.xhtml file gets displayedFigure-21 MyOwnJSF is Displayed(2.5) Access MyOwnServlet1. Right click MyFirstWebApp project node and select Properties.Figure-22 Properties3. Select Run. 4. For the Relative URL: field, type in /MyOwnServlet and Select Finish. This information is used by the NetBeans for accessing the Web application and is not part of the WAR file.Figure-23 Set Relative URL5. Right click MyFirstWebApp project node and select Run. You should see MyOwnServlet servlet is accessed as shown in Figure-2.53 below.Figure-24 MyOwnServlet accessed6. Modify the web.xml as shown below. The code fragments that need to be modified are highlighted in bold and red-colored font.web-app version=3.0 xmlns=/xml/ns/javaee MyOwnServlet MyOwnPackage.MyOwnServlet MyOwnServlet /MyOwnServletUseDifferentURL 30 faces/MyOwnJSF.xhtml 7. Right click MyFirstWebApp project node and select Run. You should experience an error.Figure-25 Error condition expected8. From your browser, go to directly to http:/localhost:8080/MyFirstWebApp/MyOwnServletUseDifferentURL(2.6) Example deployment platform1. Click Services tab window.
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 武义县2025年浙江金华武义县人力社保局所属事业单位招聘事业编制人员2人笔试历年参考题库典型考点附带答案详解(3卷合一)2套试卷
- 2025贵州黔东南州锦屏县拟聘用到县属国有企业工作笔试历年典型考点题库附带答案详解2套试卷
- 2025河北秦皇岛市市政设计院有限公司选聘高级专业技术人员拟聘用人员笔试历年备考题库附带答案详解2套试卷
- 2025广东潮州府城文化旅游投资集团有限公司下属企业副总经理岗位招聘1人笔试历年备考题库附带答案详解2套试卷
- 员工培训计划与课程开发指南
- 未来五年红油豆种子行业跨境出海战略分析研究报告
- 未来五年卷筒纸凸版印刷机行业直播电商战略分析研究报告
- 未来五年数字内容服务企业数字化转型与智慧升级战略分析研究报告
- 未来五年多层挠性印制电路板企业数字化转型与智慧升级战略分析研究报告
- 物业管理合同模板及法律风险提示
- 动物检疫大比武复习题
- 《中国法制史》自考考试知识点全覆盖测试题库(附答案)
- 寄卖行合作协议合同
- 第一章-中国心理学史
- 钢板桩支护方案施工方案
- 创建青年文明号活动台帐
- 液压辅助装置详细
- 12个月车辆安全例会
- 内科病例分析题
- 油菜高产栽培技术课件
- JJF(闽)1121-2021温度交变、冲击试验设备校准规范-(现行有效)
评论
0/150
提交评论