首页 > 代码库 > servlet

servlet

import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.Response;

/**
 * Servlet implementation class test
 */
public class test extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       
        request.setCharacterEncoding("utf-8");
        String Agent = request.getHeader("User-Agent");   
        StringTokenizer st = new StringTokenizer(Agent,";");  
        st.nextToken();  
        //得到用户的浏览器名  
        String browser = st.nextToken();  
        response.setContentType("text/html;charset=gbk");
        PrintWriter out = response.getWriter();
        String address=request.getRemoteAddr();
        String banben=request.getRemoteHost();

        StringBuffer  b = request.getRequestURL();
        String p = request.getQueryString();
        out.println("<h1>"+"remoteaddr是:"+address+"</br> remotehost是:"+banben+"</br>请求的URL是:"+b+" </br>参数是:"+p+" </br>浏览器版本是:"+browser+"<h1>");
    }



}



remoteaddr是:127.0.0.1
remotehost是:127.0.0.1
请求的URL是:http://localhost:8080/servlet/test
参数是:null
浏览器版本是: rv:40.0) Gecko/20100101 Firefox/40.0

servlet