request对象
类:
javax.servlet.HttpServletRequest
extends javax.servlet.ServletRequest内容:客户端的请求信息,如请求参数、请求类型、以及HTTP头信息等。作用域:request取得客户端输入数据:
方法 说明
getParameter (String) 返回参数内容
getParameterValues (String[]) 返回参数内容数组
范例:ch5-3.htm取得系统信息:
方法 说明
getProtocol () 返回通信协议的名称
getScheme () 返回客户端向服务器端请求的方式
getServerName () 返回服务器名称
getServerPort () 返回服务器端口号
getRemoteAddr () 返回用户的IP地址
getRemoteHost () 返回主机地址
getRealPath (String) 返回虚拟路径的真实路径
范例:ch5-4.jsp取得其他系统信息:
方法 说明
getCookies () 返回用户请求的的Cookie数组
getMethod () 返回数据传送方式
getRequestURI () 返回用户请求的网页路径
getQueryString () 返回用户附在网址列后的查询字符串
范例:ch5-5.jsp:取得请求标头信息:
方法 说明
getHeader (String) 返回指定标头的字符串内容
getDateHeader () 返回标头的时间
getIntHeader () 返回标头的值
getHeaderNames () 返回所有标头名称的字符串数组
范例:ch5-6.jsp

解决方案 »

  1.   

    <%@ page contentType="text/html;charset=gb2312"%> 
    <html>
    <title>使用request对象取得系统信息</title><body>
    <table border=1>
      <tr><td bgcolor=yellow>请求的Cookie</td>
          <td><%=request.getCookies()%></td>
      </tr>
      <tr><td bgcolor=yellow>数据传送方式</td>
          <td><%=request.getMethod()%></td>
      </tr>
      <tr><td bgcolor=yellow>要求的网页路径</td>
          <td><%=request.getRequestURI()%></td>
      </tr>
      <tr><td bgcolor=yellow>查询字符串</td>
          <td><%=request.getQueryString()%></td>
      </tr>
    </table>
    </body>
    </html>范例:ch5-6.jsp
    <%@ page contentType="text/html;charset=gb2312"%> 
    <html>
    <title>取得请求标头信息</title><body>
    <table border=1>
    <%@page import="java.util.*"%>
    <%
      Enumeration headerset = request.getHeaderNames();
      while(headerset.hasMoreElements())
      {
       String header = (String) headerset.nextElement();
       String content = request.getHeader(header);
       out.print("<tr><td bgcolor=yellow>");
       out.print(header+"</td><td>"+content+"</td></tr>");
      }
    %>
    </table>
    </body>
    </html>
      

  2.   

    5.5.1 application对象
    类:
    javax.servlet.ServletContext内容:保存共享信息。作用域:application取得服务器端的信息:
    方法 说明
    getContext (URI) 返回指定URI的ServletContext
    getMajorVersion () 返回Servlet API的版本
    getMimeType (URI) 返回指定URI的文件格式
    getRealPath (URI) 返回指定URI的实际路径
    getServletInfo () 返回服务器软件的名称和版本定义application中的数据:
    方法 说明
    getAttribute (String) 返回指定变量的内容
    getAttributeNames () 返回变量名称数组
    removeAttribute (String) 删除变量
    setAttribute (String, Object) 设定变量及其内容范例:ch5-13.jsp
      

  3.   

    是在jsp中吗?
    request.Header(String) 可以获取客户端浏览器的版本号和类型
    例如(request.getHeader("User-Agent"))
      

  4.   

    to: truss(构架) 
    是在JSP中,用request.getHeader("User-Agent")得到到是Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0),我想分开获取,可以吗?
      

  5.   

    把request.getHeader("User-Agent")传进去public class online {
    //IE用户状态
    public String[] fettle(String aa){
    String Agent[]=new String[2];
    aa=aa.replace(')',' '); String bb[]=aa.split(";");
    String ie=bb[1].trim();
    String system=bb[2].trim(); if(ie.equals("MSIE 5.01"))
    ie="Internet Explorer 5.01";
    if(ie.equals("MSIE 5.0"))
    ie="Internet Explorer 5.0";
    if(ie.equals("MSIE 6.0"))
    ie="Internet Explorer 6.0";
    if(ie.equals("MSIE 5.5"))
    ie="Internet Explorer 5.5";
    if(ie.equals("MSIE 6.0b"))
    ie="Internet Explorer 6.0b";
    if(system.equals("Windows NT 5.0"))
    system="Windows 2000";
    if(system.equals("Windows 98"))
    system="Windows 98";
    if(system.equals("Windows me"))
    system="Windows ME";
    if(system.equals("Windows NT 5.1"))
    system="windows XP";
    if(system.equals("Windows NT 5.2 .Net"))
    system="windows .Net";

    Agent[0]=ie;
    Agent[1]=system;

    return Agent;

    }
    }
    String aa[]=online.fettle(request.getHeader("User-Agent"));
    aa[0]是iE
    aa[1]是操作系统。这个处理的不全,有兴趣,可以自己在加
      

  6.   

    范例:ch5-13.jsp
    <html>
    <title>定义及取得 application 中的数据</title><body>
    <%@page import="java.util.*"%>
    <%
      String appname;
      application.setAttribute("director","郭小祯");        //自定义数据 1
    application.setAttribute("member1","张小忠");         //自定义数据 2
      application.setAttribute("member2","李小承");         //自定义数据 3
      Enumeration names = application.getAttributeNames();  //取得所有变量名
      while(names.hasMoreElements())
      {
       appname = (String) names.nextElement();    //转换变量名成字符串类型
       out.print(appname+" = ");
       out.print(application.getAttribute(appname)+"<br>"); //显示变量中的内容
      }
    %>
    </body>
    </html>
      

  7.   

    5.5.1 application对象
    类:
    javax.servlet.ServletContext内容:保存共享信息。作用域:application取得服务器端的信息:
    方法 说明
    getContext (URI) 返回指定URI的ServletContext
    getMajorVersion () 返回Servlet API的版本
    getMimeType (URI) 返回指定URI的文件格式
    getRealPath (URI) 返回指定URI的实际路径
    getServletInfo () 返回服务器软件的名称和版本
      

  8.   

    ft
    我说得是
    biggie的
    呵呵
    更新速度好快啊!