最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

request通用的代碼

2020-05-06 18:23 作者:小垃圾kiki  | 我要投稿
package cn.itcast.servlet.request;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Map;
import java.util.Set;

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

/**
?* Servlet implementation class RequestDemo6
?*/
@WebServlet("/requestDemo7")
public class RequestDemo7 extends HttpServlet {
?? ?private static final long serialVersionUID = 1L;
????? ?
??? /**
???? * @see HttpServlet#HttpServlet()
???? */
??? public RequestDemo7() {
??????? super();
??????? // TODO Auto-generated constructor stub
??? }

?? ?/**
?? ? * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
?? ? */
?? ?protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
?? ??? ?//get 獲取請求參數(shù)
//?? ??? ?String username = request.getParameter("username");
//?? ??? ?System.out.println("get");
//?? ??? ?System.out.println(username);
?? ??? ?
?? ??? ?//根據(jù)參數(shù)名稱獲取參數(shù)值的數(shù)組
//?? ??? ?String[] hobbies = request.getParameterValues("hobby");
//?? ??? ?for (String hobby : hobbies) {
//?? ??? ??? ?System.out.println(hobby);
//?? ??? ?}
?? ??? ?
?? ??? ?//獲取所有請求的參數(shù)名稱
//?? ??? ?Enumeration<String> parameterNames = request.getParameterNames();
//?? ??? ?while(parameterNames.hasMoreElements()) {
//?? ??? ??? ?String name = parameterNames.nextElement();//獲取參數(shù)名
//?? ??? ??? ?System.out.println(name);
//?? ??? ??? ?String value = request.getParameter(name);//通過參數(shù)名獲取參數(shù)值
//?? ??? ??? ?System.out.println(value);
//?? ??? ??? ?System.out.println("-----------");
//?? ??? ?}
?? ??? ?//獲取所有參數(shù)的Map集合??? 為了防止復(fù)選框獲取不到其他值的情況
?? ??? ?Map<String, String[]> parameterMap = request.getParameterMap();
?? ??? ?//遍歷
?? ??? ?Set<String> keyset = parameterMap.keySet();
?? ??? ?for (String name : keyset) {
?? ??? ??? ?//根據(jù)鍵獲取值
?? ??? ??? ?String[] values = parameterMap.get(name);
?? ??? ??? ?System.out.println(name);
?? ??? ??? ?for (String value : values) {
?? ??? ??? ??? ?System.out.println(value);
?? ??? ??? ?}
?? ??? ??? ?System.out.println("---------");
?? ??? ?}
?? ?}

?? ?/**
?? ? * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
?? ? */
?? ?protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
?? ??? ?//post 獲取請求參數(shù)
//?? ??? ?String username = request.getParameter("username");
//?? ??? ?System.out.println("post");
//?? ??? ?System.out.println(username);
?? ??? ?this.doGet(request, response);
?? ?}

}

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>注冊頁面</title>
</head>
<body>
?? ?<form action="requestDemo7" method="get">
?? ??? ?<input type="text"?? placeholder="請輸入用戶名" name="username"><br>
?? ??? ?<input type="text"? placeholder="請輸入密碼" name="password"><br>
?? ??? ?
?? ??? ?<input type="checkbox" name="hobby" value="game">游戲
?? ??? ?<input type="checkbox" name="hobby" value="study">學(xué)習(xí)<br>
?? ??? ?
?? ??? ?
?? ??? ?<input type="submit" value="注冊">
?? ??? ?
?? ?
?? ?</form>

</body>
</html>

request通用的代碼的評論 (共 條)

分享到微博請遵守國家法律
南郑县| 环江| 八宿县| 定日县| 古交市| 家居| 安康市| 大余县| 咸丰县| 潮安县| 萨迦县| 富裕县| 鄂伦春自治旗| 宾川县| 屯留县| 革吉县| 汽车| 辉县市| 广饶县| 南川市| 揭东县| 禄丰县| 大方县| 嵊州市| 涿州市| 桑植县| 罗源县| 新巴尔虎右旗| 灯塔市| 江北区| 长乐市| 深泽县| 肥东县| 阿拉尔市| 福贡县| 荥阳市| 和林格尔县| 榕江县| 汪清县| 重庆市| 阿拉善盟|