<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>

 

posted @ 2015-05-08 11:03  RyderWang  阅读(411)  评论(0编辑  收藏  举报