注册 | 登录 忘记密码? 51cto首页 | 博客 | 论坛 | 招聘
热点文章 《网络规划设计师教程》..
 帮助
技术博文专题索引
公告:
因blog评论不能上图哈,技术圈可以上图,相关RHEL5技术问题请发到企业级RedHat交流技术圈,密码验证:linuxmaster这样可以容易排障,而且时间久了,相关问题可以汇总查阅,敬请配合!
Linux:
CISCO:
JAVA EE:
2009-06-23 20:52:20



2009-06-23 07:03:25



2009-06-21 21:37:09
–典型的请求头信息
–读取HTTP请求头
–使用表格显示所有请求头信息
–理解各种请求头的含义
–区分不同的浏览器类型
##############Michael分割线###################
• 典型的请求头信息
image
• 读取HTTP请求头
–使用HttpServletRequest中的方法
• 一般方法
–getHeader (header名称不区分大小写)
–getHeaders
–getHeaderNames
• 专门方法
–getCookies
–getAuthType
–getRemoteUser
–getContentLength
–getContentType
–getDateHeader
–getIntHeader
• 相关信息
–getMethod
–getRequestURI
–getQueryString
–getProtocol
• 使用表格显示有请求头信息
image
login.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">    
<html>    
    <head>    
        <title>login.html</title>    
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">    
        <meta http-equiv="description" content="this is my page">    
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">    
        <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->    

    </head>    
    <body>    
        <form name="f1" id="f1" action="/Servlet_RequestHeader/servlet/RequestHeaderServlet" method="post">    
            <table border="0">    
                <tr>    
                    <td>Login:</td>    
                    <td><input type="text" name="login" id="login"></td>    
                </tr>    
                <tr>    
                    <td>Password:</td>    
                    <td><input type="password" name="password" id="password"></td>    
                </tr>    
                <tr>    
                    <td colspan="2" align="center"><input type="submit" value="login"></td>    
                </tr>    
            </table>    
        </form>    
    </body>    
</html>

image
RequestHeaderServlet.java

package com.michael.servlet;    

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

import javax.servlet.ServletException;    
import javax.servlet.http.HttpServlet;    
import javax.servlet.http.HttpServletRequest;    
import javax.servlet.http.HttpServletResponse;    

public class RequestHeaderServlet extends HttpServlet {    

        /**    
         * Constructor of the object.    
         */    
        public RequestHeaderServlet() {    
                super();    
        }    

        /**    
         * Destruction of the servlet. <br>    
         */    
        public void destroy() {    
                super.destroy(); // Just puts "destroy" string in log    
                // Put your code here    
        }    

        /**    
         * The doGet method of the servlet. <br>    
         *    
         * This method is called when a form has its tag value method equals to get.    
         *    
         * @param request the request send by the client to the server    
         * @param response the response send by the server to the client    
         * @throws ServletException if an error occurred    
         * @throws IOException if an error occurred    
         */    
        public void doGet(HttpServletRequest request, HttpServletResponse response)    
                        throws ServletException, IOException {    

                doPost(request,response);    
        }    

        /**    
         * The doPost method of the servlet. <br>    
         *    
         * This method is called when a form has its tag value method equals to post.    
         *    
         * @param request the request send by the client to the server    
         * @param response the response send by the server to the client    
         * @throws ServletException if an error occurred    
         * @throws IOException if an error occurred    
         */    
        public void doPost(HttpServletRequest request, HttpServletResponse response)    
                        throws ServletException, IOException {    
                Enumeration names = request.getHeaderNames();                

                response.setContentType("text/html");    
                PrintWriter out = response.getWriter();    
                out    
                                .println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");    
                out.println("<HTML>");    
                out.println("    <HEAD><TITLE>A Servlet</TITLE></HEAD>");    
                out.println("    <BODY>");    

                out.println("<table>");    
                out.println("<tr>");    
                out.println("<th>");    
                out.println("RequestHeader Name");    
                out.println("</th>");    
                out.println("<th>");    
                out.println("RequestHeader Value");    
                out.println("</th>");    
                out.println("</tr>");    
                while(names.hasMoreElements()){    
                        String name = (String) names.nextElement();    
                        String value = request.getHeader(name);    
                        out.println("<tr>");    
                        out.println("<td>");    
                        out.println(name);    
                        out.println("</td>");    
                        out.println("<td>");    
                        out.println(value);    
                        out.println("</td>");    
                        out.println("</tr>");    
                }    
                out.println("</table>");    
                out.println("    </BODY>");    
                out.println("</HTML>");    
                out.flush();    
                out.close();    
        }    

        /**    
         * Initialization of the servlet. <br>    
         *    
         * @throws ServletException if an error occure    
         */    
        public void init() throws ServletException {    
                // Put your code here    
        }    

}




2009-06-21 05:49:54



2009-06-20 21:53:06



2009-06-19 21:43:25



2009-06-19 21:07:18



2009-06-16 22:51:15



2009-06-15 16:38:36



2009-06-14 22:36:02



 <<   1   2   3   4   5   >>   页数 ( 1/37 )