关键词

<fmt:requestEncoding>标签

JSTL <fmt:requestEncoding> 标签作用与 request.setCharacterEncoding("charsetName") 相同,用于设置请求数据的字符编码。

语法

JSP <fmt:requestEncoding> 标签语法如下:
<fmt:requestEncoding value="charsetName">
其中,value 用来指定字符编码。

示例

下面为 <fmt:requestEncoding> 标签的简单实例。

login.jsp 代码如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8a"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html>
<html>
<head>
<title>编程帮(www.lmcjl.com)</title>
</head>
<body>
<body>
    <form action="index.jsp" method="post">
        关键字:<input name="key" /> <br /> <br />
        <input type="submit">
    </form>
</body>
</html>
index.jsp 代码如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html>
<html>
<head>
<title>编程帮(www.lmcjl.com)</title>
</head>
<body>
<body>
    <fmt:requestEncoding value="UTF-8" />
    <c:out value="${param.key}"></c:out>
</body>
</html>

运行结果如下:



本文链接:http://task.lmcjl.com/news/15949.html

展开阅读全文