JSP:
pageEncoding="UTF-8"%>
Insert title herehello
Servlet:
package com.cs.helloworld;
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;
@WebServlet("/test")
public class TestHttpServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String name = request.getParameter("username");
System.out.println(name);
PrintWriter pw = response.getWriter();
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
pw.print("name:"+name);
String AythType = request.getAuthType();
System.out.println("AythType"+AythType);
//String getContextPath()
String ContextPath = request.getContextPath();
System.out.println("ContextPath"+ContextPath);
String QueryString = request.getQueryString();
System.out.println("QueryString"+QueryString);
String method = request.getMethod();
System.out.println(method);
}
}
结果如下:
name:xiaoshideyu
AythType:null
ContextPath:/FirstHello
QueryString:username=xiaoshideyu
methodGET