//这个代码不可以写在javase的project文件里面
//要写在动态web工程里面,不需要配置文件,不需要jsp,只需jar包的帮助(url跳转的必须是java-web文件)
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//就不用xml 注解了
1 //地址栏输入helloworld http://localhost:8080/项目名/HelloWorld1
// 输出helloworld1
2 @WebServlet("/HelloWorld1")
3 public class HelloWorld1 extends HttpServlet {
4 // 主要是这个函数
5 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletExcep tion, IOException {
6 response.setContentType("text/html");
7 PrintWriter out = response.getWriter();
8 out.println("<b>Hello World</b>");
9 }
10
11 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletExce ption, IOException {
12 doGet(request, response);
13 }
14 }