立即学习:https://edu.csdn.net/course/play/1060/15783?utm_source=blogtoedu
7. 第一个 WEB 应用程序:开发,并部署到 Tomcat 服务器下运行
1). 在 Eclipse 新建一个 Java Project
2). 在 Java 项目下创建 WEB 开发的目录结构
-WebContent
- WEB-INF
-- classes (编译后的 class 文件必须放在该目录下 .)
-- lib
-- web.xml
html 页面
JSP 页面
图片 ...
3). 在 src 下新建一个 Person 类
package com.tywl.javaweb;
public class Person {
public String getPersoninfo() {
return "person info ...";
}
}
4). 手工把 Person 类对应得 class 文件(包含)复制到 classes 下
可以通过修改默认得输出目录达到自动编译好得 class 放到 classes 目录下:
5). 在 WebContent 下新建一个JSP 文件
<%@page import="com.tywl.javaweb.Person"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%
Person person = new Person();
System.out.print(person.getPersoninfo());
%>
6). 把 WebContent 目录复制到 Tomcat 得 webapps 目录下,并改名为: helloworld
7). 在浏览器得地址栏中输入: http://localhost:8080/helloworld/hello.jsp 即可看到命令行下打印得信息