JSP request(return String)用法详例

1.JSP代码 :


代码如下:

<%--
Document : index
Created on : 2009-10-4, 12:45:43
Author : lucifer
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
get Scheme:
<%=request.getScheme()%>
<br>
get Protocol:
<%=request.getProtocol()%>
<br>
get Remote Address:
<%=request.getRemoteAddr()%>
<br>
get Remote Host:
<%=request.getRemoteHost()%>
<br>
get Server Name:
<%=request.getServerName()%>
<br>
get Server Port:
<%=request.getServerPort()%>
<br>
get Header:
<%=request.getHeader("User-agent")%>
<br>
get Method:
<%=request.getMethod()%>
<br>
get Request's URL:
<%=request.getServletPath()%>
<br>
get Request URI:
<%=request.getRequestURI()%>
<br>
get Request Session ID:
<%=request.getRequestedSessionId()%>
</body>
</html>

2.输出:
get Scheme: http
get Protocol: HTTP/1.1
get Remote Address: 0:0:0:0:0:0:0:1
get Remote Host: 0:0:0:0:0:0:0:1
get Server Name: localhost
get Server Port: 8084
get Header: Mozilla/5.0 (Windows; U; Windows NT 6.0; zh-CN; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3
get Method: GET
get Request's URL: /Requests.jsp
get Request URI: /TestRequest/Requests.jsp
get Request Session ID: 6EF4EB4A3FE39A15EEBD4D46FBD0BA32

(0)

相关推荐

  • 通过过滤器(Filter)解决JSP的Post和Request中文乱码问题

    jsp代码: import javax.servlet.*; import javax.servlet.http.*; public class CharsetFilter implements Filter { public void destroy() { } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) { try { HttpServletRequest

  • JSP XMLHttpRequest动态无刷新及其中文乱码处理

    1.在页面的<script type="text/JavaScript" >内加入 //无刷新请求的xmlhttp请求 var http_request=false; function createRequest(url) { http_request = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... http_request = new XMLHttpRequest(); if (http_reque

  • JSP用过滤器解决request getParameter中文乱码问题

    (1)客户端的数据一般是通过HTTP GET/POST方式提交给服务器,在服务器端用request.getParameter()读取参数时,很容易出现中文乱码现象. (2)用过滤器解决request中文乱码问题. (3)代码如下: package my; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class ChineseFilter implements Filter { //定义

  • java和jsp中的request使用示例

    复制代码 代码如下: //== JAVA request 详细说明== System.out.println("rotocol: " + request.getProtocol());  System.out.println("Scheme: " + request.getScheme());  System.out.println("Server Name: " + request.getServerName() );  System.out.

  • jsp跳转getRequestDispatcher()和sendRedirect()的区别

    1.request.getRequestDispatcher()是请求转发,前后页面共享一个request ;response.sendRedirect()是重新定向,前后页面不是一个request. 2.RequestDispatcher.forward()是在服务器端运行;HttpServletResponse.sendRedirect()是通过向客户浏览器发送命令来完成.所以RequestDispatcher.forward()对于浏览器来说是"透明的":而HttpServlet

  • JSP request.setAttribute()详解及实例

     javascript request.setAttribute()详解 request.setAttribute()怎么用的? JSP1代码 String [] test=new String[2]; test[0]="1"; test[1]="2"; request.setAttribute("test",test) ; response.sendRedirect("jsp2.jsp"); JSP2代码 String te

  • JSP的request对象实例详解

    JSP的request对象实例详解 一 request对象定义 客户端的请求信息被封装在request对象中,通过它才能了解客户的需求,然后做出响应.它是HttpServletRequest类的实例.request对象具有请求域,即完成客户端的请求之前,该对象一直有效. 二 request对象方法 三 实例 <%@ page language="java" import="java.util.*" contentType="text/html; ch

  • JSP内置对象:Request和Response的简单介绍及使用

    JSP内置对象之request对象客户端的请求信息被封装在request对象中,通过它才能了解到客户的需求,然后做出响应.它是HttpServletRequest类的实例.序号 方 法 说 明 1 object getAttribute(String name) 返回指定属性的属性值 2 Enumeration getAttributeNames() 返回所有可用属性名的枚举 3 String getCharacterEncoding() 返回字符编码方式 4 int getContentLen

  • JSP利用过滤器解决request中文乱码问题

    本文为大家分享了JSP用过滤器解决request中文乱码问题,具体内容如下 (1)客户端的数据一般是通过HTTP  GET/POST方式提交给服务器,在服务器端用request.getParameter() 读取参数时,很容易出现中文乱码现象. (2)用过滤器解决request中文乱码问题. (3)代码如下: package my; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public clas

  • jsp 对request.getSession(false)的理解(附程序员常疏忽的一个漏洞)

    [前面的话] 在网上经常看到有人对request.getSession(false)提出疑问,我第一次也很迷惑,看了一下J2EE1.3 API,看一下官网是怎么解释的. [官方解释] getSession public HttpSession getSession(boolean create) Returns the current HttpSession associated with this request or, if if there is no current session an

随机推荐