<jsp:param>传参乱码问题

在添加参数的界面添加<%request.setCharacterEncoding("UTF-8");%>

实例代码:

login_confirm.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!-- 解决jsp:param传参乱码问题 -->
<%request.setCharacterEncoding("UTF-8");%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>登录验证界面</title>
</head>
<body>
<c:if test="${param.username==\"123\" && param.userpass==\"123456\"}">
<!-- 把用户信息添加到session-->
<c:set var="username" value="${param.username}" scope="session"/>
<jsp:forward page="login_success.jsp"/>
</c:if>

<c:if test="${param.username !=\"123\"}">
<jsp:forward page="login_failure.jsp">
<jsp:param name="info" value="用户名不正确"/>
</jsp:forward>
</c:if>
<c:if test="${param.userpass!=\"123456\"}">
<jsp:forward page="login_failure.jsp">
<jsp:param name="info" value="用户口令不正确"/>
</jsp:forward>
</c:if>

</body>
</html>

login_failure.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>登录成功界面</title>
</head>
<body>
登录失败,错误信息如下:${param.info}
<div align="center">
    <a href="index.jsp">重新登录</a>
</div>
</body>
</html>

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。