程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> JSP編程 >> 關於JSP >> jsp request.getParameter()接受表單和url數據代碼

jsp request.getParameter()接受表單和url數據代碼

編輯:關於JSP

request.getParameter()方法傳遞的數據,會從Web客戶端傳到Web服務器端,代表HTTP請求數據。request.getParameter()方法返回String類型的數據。

 

<%@ page import="java.util.*" %>
<%
   String title = "HttpServletRequest Method Values";
   Map entries = new TreeMap();
   entries.put("getCharacterEncoding", request.getCharacterEncoding());
   entries.put("getContentLength", "" + request.getContentLength());
   entries.put("getContentType", request.getContentType());
   entries.put("getLocale", request.getLocale());
   entries.put("getProtocol", request.getProtocol());
   entries.put("getRemoteAddr", request.getRemoteAddr());
   entries.put("getRemoteHost", request.getRemoteHost());
   entries.put("getScheme", request.getScheme());
   entries.put("getServerName", request.getServerName());
   entries.put("getServerPort", "" + request.getServerPort());
   entries.put("isSecure", "" + request.isSecure());
   request.setAttribute("_table_title", title);
   request.setAttribute("_table_entries", entries);
  
   out.println(request.getCharacterEncoding());
%>

request.getParameter()取得是通過容器的實現來取得通過類似post,get等方式傳入的數據

 

   <H1> Request Information </H1>
        JSP request method: <%= request.getMethod() %>
        <BR>
        URL for the request: <%= request.getRequestURI() %>
        <BR>
        Protocol of the request: <%= request.getProtocol() %>
        <BR>
        Server name: <%= request.getServerName() %>
        <BR>
        Path: <%= request.getServletPath() %>
        <BR>
        Server port: <%= request.getServerPort() %>
        <BR>
        Remote address: <%= request.getRemoteAddr() %>
        <BR>
        Remote host: <%= request.getRemoteHost() %>
        <BR>
        Locale: <%= request.getLocale() %>
        <BR>
        User agent: <%= request.getHeader("User-Agent") %>


來自get 數據

<html>
<head>
<title>Retrieving the Original URI</title>
</head>
<body>
<pre>
In ShowPath1.jsp教程:

   request.getRequestURI() =
      <%= request.getRequestURI() %>

   request.getServletPath() =
      <%= request.getServletPath() %>

</pre>
<jsp:include page="ShowPath2.jsp" flush="true"/>
</body>
</html>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved