使用Eclipse和Tomcat开发Web程序
来源:互联网 发布:上海开放大学网络教育 编辑:程序博客网 时间:2024/05/22 06:48
一、配置Runtime Environment
打开Eclipse jee后,在菜单选择Window-->Preferences,打开配置
选择Server目录下的Runtime Environment,点击Add增加新的运行环境
选择自己安装的Tomcat版本,点击Next
选择Tomcat安装目录为自己的安装目录,JRE为自己安装的jre
点击Finish完成配置
二、创建项目
在菜单栏选择File-->New-->Dynamic Web Project,创建项目
设置项目名称,并选择Target runtime为刚刚配置的运行时环境
点击Next,在如下页面时选择复选框
点击Finish完成创建,得到项目工程
三、创建jsp页面
在WebContent目录下新建一个jsp文件
编辑jsp文件
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>My first tomcat demo</title></head><body><%out.println("Hello world!");%></body></html>
在菜单栏选择Window-->Web Browser-->Default system web browser,选择启动默认浏览器
在菜单选择Run-->Run As-->Run on Server,启动项目
此时浏览器会弹出Web页面
因为项目会自动启动服务器,所以如果在之前已经启动了服务器,那么就会弹出如下错误,关掉服务器重试即可。
四、创建Servlet实例
在菜单选择File-->New-->Servlet,创建Servlet实例
更改Java package和Class name,我这里创建创建一个简单的ServletDemo例子
创建完成后,修改ServletDemo.java中的代码,这里作为例子只修改了doGet方法,输出一条Hello servlet!
/** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubresponse.getWriter().write("Hello servlet!\n");response.getWriter().append("Served at: ").append(request.getContextPath());}
打开文件目录下的web.xml文件,具体为TomcatDemo/WebContent/WEB-INF/web.xml
修改其中代码
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>TomcatDemo</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <servlet> <!-- 类名 --> <servlet-name>ServletDemo</servlet-name> <!-- 所在的包 --> <servlet-class>com.example.ServletDemo</servlet-class> </servlet> <servlet-mapping> <servlet-name>ServletDemo</servlet-name> <!-- 访问的网址 --> <url-pattern>/TomcatDemo/ServletDemo</url-pattern> </servlet-mapping></web-app>
重新运行代码,需要重启服务器。访问http://localhost:8080/TomcatDemo/ServletDemo
- 使用Eclipse和Tomcat开发Web程序
- eclipse+tomcat开发web程序
- eclipse+tomcat开发web程序
- eclipse+tomcat开发web程序
- eclipse和tomcat开发web
- Eclipse和Tomcat开发web
- 【转载】eclipse+tomcat开发web程序
- 使用eclipse+maven+tomcat开发web应用
- 用 Tomcat 和 Eclipse 开发 Web 应用程序
- 用 Tomcat 和 Eclipse 开发 Web 应用程序
- 用 Tomcat 和 Eclipse 开发 Web 应用程序
- 用 Tomcat 和 Eclipse 开发 Web 应用程序
- 用 Tomcat 和 Eclipse 开发 Web 应用程序
- 用 Tomcat 和 Eclipse 开发 Web 应用程序
- 用 Tomcat 和 Eclipse 开发 Web 应用程序
- 用Tomcat和Eclipse开发Web 应用程序
- 用 Tomcat 和 Eclipse 开发 Web 应用程序
- 用 Tomcat 和 Eclipse 开发 Web 应用程序
- 世界互联网大会溢出效应:比大佬饭局更值得关注的是产业互联网
- cortex m7 架构 随笔
- java第三篇 泛型的了解与使用
- 利用kattle将SQLserver中的数据导入到vertica中
- 蓝桥杯 算法训练 传纸条
- 使用Eclipse和Tomcat开发Web程序
- (转)孙正义:数字资产会成为人类最大的资产
- 我在xxx公司的日子(2)
- Java-----分布式锁
- Spring AOP事物异常 but was actually of type 'com.sun.proxy.$Proxy17
- Android样式 Selector
- 【Weblogic】 Weblogic Server环境下使用JMS服务
- 修改vs2010发布包【发布文件】
- 关于sql中出现的三种多线程操作