為什么我用提交按鈕提交會是這樣,名字輸入的中文,下面的愛好后面是啥?
User:
??
frivious:[Ljava.lang.String;@24ca1465
read
swam
password:123?
我的代碼
request.jsp:
<%@ 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 'request.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>inner request</h1>
? <%
??
? String expr = new String(request.getParameter("Username").getBytes("ISO-8859-1"),"UTF-8");?
? request.setCharacterEncoding("utf-8");
? request.setAttribute("password", "123");
? %>
? User: <%=expr %><br>
? frivious:<%=request.getParameterValues("frivious") %><br>
? <%
? if(request.getParameterValues("frivious")!=null){
? String[] frivious=request.getParameterValues("frivious");
? for(int i=0;i<frivious.length;i++){
? out.print(frivious[i]+"<br>");
? }
? }
? ?%>
? ?password:<%=request.getAttribute("password")%>
? </body>
</html>
=====================================
=============req.jsp:========================
<%@ 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 'req.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>
? ?<form name="req" action="request.jsp" method="get">
? ?<table>
? ?<tr>
? ?<td>Username</td>
? ?<td><input type="text" name="Username"></td>
? ?</tr>
? ?<tr>
? ?<td>fravious</td>
? ?<td><input type="checkbox" name="frivious" value="read">read
? ?<input type="checkbox" name="frivious" value="music">music
? ?<input type="checkbox" name="frivious" value="swam">swam
? ?<input type="checkbox" name="frivious" value="foot">foot
? ??
? ?</td>
? ?</tr>
? ?<tr>
? ?<td colspan="2"><input type="submit" value="value"></td>
? ?</table>
??
? ?</form>
? ?<br>
? ?<br>
? ? <a href="request.jsp?Username=王五">test of the URl</a>
? </body>
</html>
2016-02-28
親,我覺得你的favorites(frivious)輸出的結(jié)果是“[Ljava.lang.String;@24ca1465”的原因是因為你直接輸出了一個數(shù)組,這樣是不正確的,你的這種行為類似于out.print(s),其中s是數(shù)組,二對于s你不應該直接輸出它,而是應該依次輸出其中的元素。