<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>用户登录界面</title>
</head>
<body>
<form name="form1" method="post" action="result.jsp">
用户名: <input name="name" type="text" id="name" style="width: 120px" ><br>
密 码: <input name="password" type="text" id="password" style="width:120px"><br>
<br>
<input type="submit" name="Submit" value="提交">
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>result.jsp</title>
</head>
<body>
<%
String name=request.getParameter("name");
String password=request.getParameter("password");
%>
<from id="form1" method="post" action="">
<table width="28%" border="0">
<tr>
<td width="49%"><div align="left">您的名字是:</div></td>
<td width="51" ><label>
<div align="left"><%=name %></div>
</label></td>
</tr>
<tr>
<td width="49%"><div align="left">您的密码是:</div></td>
<td width="51%"><label>
<div align="left"> <%=password %></div>
</label></td>
</tr>
</table>
</from>
</body>
</html>
这里如果用户输入的用户名是中文的话,则在result.jsp页面显示时,中文内容变成了乱码
只需将“String name=request.getParameter("name");”改为
“String name=new String(request.getParameter("name").getBytes("ISO-8859-1"),"UTF-8");”就可以解决中文乱码问题
本文地址:https://blog.csdn.net/qq_46048366/article/details/107384639
如对本文有疑问, 点击进行留言回复!!
idea 访问html页面端口号显示的是63342而不是8080
网友评论