码迷,mamicode.com
首页 > 其他好文 > 详细

servlet

时间:2016-12-07 20:45:20      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:prot   ade   protected   head   oge   charset   xtend   cte   tchar   

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

标签:prot   ade   protected   head   oge   charset   xtend   cte   tchar   

原文地址:http://www.cnblogs.com/helloaworld/p/6142421.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!