1 / 25

Tomcat 的安装和配置

软件平台技术( J2EE ). Tomcat 的安装和配置. 任课老师:邱明. Tomcat 简介. 什么是 Tomcat? 由  Apache  组织开发的一个  Servlet/JSP  容器,由纯  Java  开发完成的 Tomcat 有什么用 ? 负责解析和运行 Servlet 和 JSP JAVA Web Project 需要放在 tomcat 中才能被编译和运行. MyEclipse + Eclipse + Apache Tomcat 的搭建过程. 一 . 安装 j2sdk1.5 ,设定环境变量

ludwig
Download Presentation

Tomcat 的安装和配置

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 软件平台技术(J2EE) Tomcat 的安装和配置 任课老师:邱明

  2. Tomcat简介 • 什么是Tomcat? • 由 Apache 组织开发的一个 Servlet/JSP 容器,由纯 Java 开发完成的 • Tomcat有什么用? • 负责解析和运行Servlet和JSP • JAVA Web Project需要放在tomcat中才能被编译和运行

  3. MyEclipse + Eclipse + Apache Tomcat的搭建过程 • 一. 安装j2sdk1.5,设定环境变量 • 操作: My Computer(右键) ----> Properties ----> Advanced ----> Environment Variables • 设定环境变量为:1. 新建JAVA_HOME: (jdk安装目录)假设为D:\j2sdk 2. 新建CLASSPATH: .;D:\j2sdk\lib\dt.jar;D:\j2sdk\lib\tools.jar (注意:点号不能省略,表示当前目录)3. 编辑PATH的变量值,在后面加上 ;%JAVA_HOME%\bin (注意:要有分号隔开)

  4. MyEclipse + Eclipse + Apache Tomcat的搭建过程 • 二. 安装Tomcat • 下载一个Tomcat的zip版本,直接解压到某一个盘即可(ftp提供最新版本的下载) • 测试Tomcat是否安装成功可以运行Tomcat安装目录下\bin下的startup.bat批处理文件,然后打开一个IE输入http://localhost:8080看是否出现Apache tomcat的页面。

  5. MyEclipse + Eclipse + Apache Tomcat的搭建过程 • 三. 安装Eclipse(示例安装的版本为3.2) • 解压Eclipse到某一个路径下即可。

  6. MyEclipse + Eclipse + Apache Tomcat的搭建过程 • 三. 安装MyEclipse(示例安装的版本为5.0.1GA_E3.2.) • 安装过程中选择上一步eclipse所在的目录,其它都直接点击下一步,默认安装。 • 然后启动eclipse设置相应参数

  7. 选择tomcat所在目录

  8. 在此设计你所要的页面格式

  9. 注意:为了支持中文显示,最好在每个jsp页面的顶部加上以下语句:注意:为了支持中文显示,最好在每个jsp页面的顶部加上以下语句: <%@ page contentType="text/html;charset=GB2312" %> <%request.setCharacterEncoding("GB2312");%>

  10. Example2

  11. Login.jsp 填写用户信息 Dispatcher.java 控制页面的跳转 Dispalay.jsp 显示用户填入的信息

  12. Login.jsp代码 • <body> • <div align="center"><br>Login On<br> • </div><form name="loginForm" action="Dispatcher" method="POST"><div align="center"> • </div> • <div align="center"><table width="200" border="1"> • <tbody><tr> • <td align="center">Username<br></td> • <td>&nbsp; • <input type="text" name="username"></td></tr> • <tr> • <td>&nbsp;Password</td> • <td>&nbsp;<input type="password" name="password"></td></tr> • <tr> • <td >&nbsp;<input type="reset" value="重置" name="reset"></td> • <td>&nbsp;<input type="submit" value="提交" name="submit"></td></tr> • </tbody></table></div>> • </form> </body>

  13. Display.jsp代码 • <body> • <b>Hello, <%=request.getAttribute("USER") %> ,Welcome to J2EE World! <br> • </body>

  14. Dispatcher.java代码 保证页面跳转时中文字符能正确传递 • request.setCharacterEncoding("GB2312"); • //Get username from the request • String username=request.getParameter("username"); • //Get password from the request • String password=request.getParameter("password"); • //Add user to request • request.setAttribute("USER", username); • request.setAttribute("PASSWORD", password); • //Forward the request to display • ServletContext context=getServletContext(); • System.out.println("Redirecting to "+ "/display.jsp"); • RequestDispatcher dispatcher= • context.getRequestDispatcher("/display.jsp"); • dispatcher.forward(request,response);

  15. 在新建一个servlet时会生成一个web.xml的文件。它的作用是控制web应用的行为。在此范例中为了实现页面的正确跳转,必须配置web.xml在新建一个servlet时会生成一个web.xml的文件。它的作用是控制web应用的行为。在此范例中为了实现页面的正确跳转,必须配置web.xml • <servlet> • <description>This is the description of my J2EE component</description> • <display-name>This is the display name of my J2EE component</display-name> • <servlet-name>Dispatcher</servlet-name> • <servlet-class>mypack.Dispatcher</servlet-class> • </servlet> • <servlet-mapping> • <servlet-name>Dispatcher</servlet-name> • <url-pattern>/Dispatcher</url-pattern> • </servlet-mapping> • </web-app> • 更详细的属性介绍可阅读此网页的文章http://www.diybl.com/course/4_webprogram/xml/xml_js/20071128/88156.html Servlet文件所在的包 Servlet的名字,需保持一致 url的映射配置 要修改默认的url可以相应的修改此地方

More Related