准备条件
- eclipse
- jdk1.8 (配置jdk环境)
- apache-tomcat-8.5.97(记住安装位置)
一
点击完成
开始创建javaweb项目
java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class test extends HttpServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 获取 PrintWriter 对象
response.setCharacterEncoding("UTF-8");
response.setContentType("text/plain; charset=UTF-8");
PrintWriter pw = response.getWriter();
// 输出 Hello World
pw.print("输出 Hello World");
}
}
目录结构如下:
java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class test extends HttpServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 获取 PrintWriter 对象
response.setCharacterEncoding("UTF-8");
response.setContentType("text/plain; charset=UTF-8");
PrintWriter pw = response.getWriter();
// 输出 Hello World
pw.print("输出 Hello World");
}
}