用戶名為null
這是reg:
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
? <head>
? ? <base href="<%=basePath%>">
? ??
? ? <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0"> ? ?
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
? </head>
??
? <body>
? ? <h1>用戶注冊</h1>
? ? <hr>
? ? <form name = "regForm" action = "request.jsp" method= "post">
? ? <table>
? ? ?<tr>
? ? ? <td>用戶名:</td>
? ? ? <td><input type = "text" name = "username"></td>
? ? ?</tr>
? ? ?<tr>
? ? ? <td>愛好:</td>
? ? ? <td>
? ? ? ?<input type = "checkbox" name = "favorite" value = "read">讀書
? ? ? ?<input type = "checkbox" name = "favorite" value = "movie">電影
? ? ? ?<input type = "checkbox" name = "favorite" value = "music">音樂
? ? ? ?<input type = "checkbox" name = "favorite" value = "internet">上網(wǎng)
? ? ? </td>
? ? ?</tr>
? ? ?<tr>
? ? ? <td colspan ="2"><input type = "submit" value = "提交">
? ? ? </td>?
? ? ?</tr>
? ? </table>
? ? </form>
? ? <br>
? ? <br>
? ? <a href="request.jsp?username=lisi">測試url傳參數(shù)</a>?
? </body>
</html>
--------------------------------------------------------------------------------------
這是request:
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%
String path = request.getContextPath();?
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
? <head>
? ? <base href="<%=basePath%>">
? ??
? ? <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0"> ? ?
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
? </head>
??
? <body>
? ? <h1>request內(nèi)置對象</h1>
? ? <%
? ? ?request.setCharacterEncoding("utf-8") ;
? ? %>
? ? ? ? ? ? ? ? ? ? ?用戶名:<%=request.getParameter("username")%><br>
? ? ? ? ? ? ? ? ? ? ?愛好:<%
? ? ? ? ? ? ? ? ? ?if(request.getParameterValues("favorite")!=null)
? ? ? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ?String[] favorites = request.getParameterValues("favorite");
? ? ? ? ? ? ? ? ? ?for(int i =0;i<favorites.length;i++)
? ? ? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ? ?out.println(favorites[i]+"<br>"+"  ");
? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?%>
? ? ?
? </body>
</html>
2017-11-13
我也是名字為null
2017-08-11
我看一下 代碼應(yīng)該是對的呀。。。。。我的可以
<%
? ?request.setCharacterEncoding("utf-8");
? //解決用戶信息用中文是的亂碼,但是無法解決url傳遞參數(shù)亂碼問題
? request.setAttribute("password","miaomiao");
? %>
? 用戶名:<%=request.getParameter("username") %><br>
? 愛好:<%
??
? String[] favorite=request.getParameterValues("favorite");
? for(int i=0;i<favorite.length;i++)
? {
?out.println(favorite[i]+" ");
? }
?
? %>
2017-08-07
中文名字可以 而且沒出現(xiàn)亂碼