在获取用户名的时候,中文显示不出来,但基本的编码方式都已经改成了 utf-8,仍然没用,这个问题怎么解决呢?
表单
<%@ page language="java" import="java.util.*,java.text.*,java.sql.*,java.io.*,javax.servlet.*" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@page import="JavaBean.Users" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="mycss/login.css" type="text/css"/>
<style>
body{
background-size:cover;
background-image:url(images/bg_login.jpg);
}
</style>
</head>
<body>
<div id="login">
<form action="test.jsp" method="post" name="loginForm">
<img src="images/logo_login.png" id="logo">
<table >
<tr>
<td><input id="user" type="text" disabled="true" placeholder="用户名:"></td>
<td><input id="userText" type="text" name="username"></td>
</tr>
<tr>
<td><input id="user" type="text" disabled="true" placeholder="密码:"></td>
<td><input id="userText" type="password" name="password"></td>
</tr>
<tr>
<td></td>
<td id="sub"> <input id="submit" type="submit" name="submit" value="登录"> </td>
</tr>
</table>
</form>
</div>
</body>
</html>
//***********对表单匹配
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@page import="JavaBean.Users" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>、
<jsp:useBean id="myUser" class="JavaBean.Users" scope="page"></jsp:useBean>
<h1>setPropert动作元素</h1>
<hr>
<!-- 根据表单自动匹配所有的属性 -->
<jsp:setProperty name="myUser" property="*"/>
用户名:<%=myUser.getUsername() %>
密码:<%=myUser.getPassword() %>
</body>
</html>
//****************JAvaBean:
package JavaBean;
public class Users {
private String username;//用户名
private String password;//密码
public Users() {
}
//对私有变量进行get,set封装
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}