demo
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <a href="index.do">点击我</a>> </body> </html>
package com.test;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
/**
* doPost方法不支持 a 标签和地址栏直接输入地址访问
*
* 测试方法1:把这个servlet只保留 doPost 方法,然后浏览器访问:127.0.0.1:8000/index.do
* 测试方法2:把这个servlet只保留 doPost 方法,然后浏览器访问:127.0.0.1:8000/index.html,然后再点击页面的链接
* 反证方法: 把这个servlet只保留 doGet 方法,一切正常
*/
@WebServlet("/index.do")
public class Index extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html; charset=UTF-8");
PrintWriter out = response.getWriter();
out.println("success");
out.close();
}
}