web.xml配置:
jsp代码:
注意:action书写的是为这次登陆做处理类的别名,method就是请求的方式
Get请求方式没有请求实体
//如果只是看效果就光写一下service方法就行了 package com.zyb.test; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.sun.java_cup.internal.runtime.Symbol; public class TestServlet extends HttpServlet { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.getWriter().write("test file");//打印在页面上 System.out.println("test file");//打印在控制台 } @Override public void init() throws ServletException { System.out.println("Servlet初始化完成!"); } public void destory() { System.out.println("Servlet销毁完成!"); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("我是doPost方法!"); } @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("我是doGet方法!"); } }
最终效果: