jsp乱码问题 URL传值乱码问题
jsp乱码问题解决
1、一般的jsp页面显示乱码
<%@ page contentType="text/html; charset=UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
2、表单提交中文时出现乱码
如果jsp提交英文字符能正确显示,而提交中文时就会出现乱码。
原因:浏览器默认使用UTF-8编码方式来发送请求,而UTF- 8和GB2312编码方式表示字符时不一样,
这样就出现了不能识别字符
解决:再jsp页面设定 <%request.seCharacterEncoding("UTF-8");%>对请求进行统一编码
为了避免每页都要写request.setCharacterEncoding("UTF-8"),建议使用过滤器对所有jsp
进行编码处理,
过滤器——.java文件:
public class SetCharacterEncodingFilter implements Filter{
/*过滤器,解决中文乱码问题*/
protected String encoding = "UTF-8";
protected FilterConfig filterConfig = null;
protected boolean ignore = true;
public void destroy() {
// TODO Auto-generated method stub
this.encoding = null;
this.filterConfig = null;
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
try {
// Conditionally select and set the character encoding to be used
if (ignore || (request.getCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null)
request.setCh
相关文档:
上网看了好多,就这一篇解决了我的问题,现转,我的项目用的是MVC架构,有统一的控制器,转向不同的Action,上网看了好多,大部分是说加入request.setCharacterEncoding("utf-8");但是经过我的试验,这只有在利用JSP处理表单传输数据时才可用,在我的东西中无法解决,后来发现还是用FilterChain好,呵呵,重点还是在request ......
注释
在客户端显示一个注释.
JSP 语法
<!-- comment [ <%= expression %> ] -->
例子 1
<!-- This file displays the user login screen -->
在客户端的HTML源代码中产生和上面一样的数据:
<!-- This file displays the user login screen -->
例子 2
<!-- This page was lo ......
复选框的使用及JSP对数据的处理
<!--
Description: HTML表单复选框及JSP处理测试
Author: pxzl
Date: 2009-08-05 15:12:43
-->
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
String[] cheArray1=request.getParameterValues("chkbox1");
String[] cheArray2=req ......
member.jsp //session限制访问页
<%
String url = ""
if(session.getAttribute("username")==null)
{
url = myRedirect.dealurl(request);//记录当前地址和请求参数,dealurl将实际url处理了避免和要请求url有干扰,因为会有& 字符
......