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
相关文档:
自动转向,也叫自动重定向。自动跳转,指当访问用户登陆到某网站时,自动将用户转向其它网页地址的一种技术。转向的网页地址可以是网站内的其它网页,也可以是其它网站。通常情况下,浏览器会收到一个网页,该页面含有自动加载一其它网页的代码。该页面有可能在服务器端被转换,这样的话,浏览器只收到一个页面,而自动转 ......
下面的jsp和数据库连接大全,请参考
一、jsp连接Oracle8/8i/9i数据库(用thin模式)
testoracle.jsp如下:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
Stri ......
注释
在客户端显示一个注释.
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程序时,常常会碰到中文字符处理的问题,在接受request的中文字符时显示出来一串乱码。网上处理方法一箩筐,下面说说我用过的两种有效地解决办法:
1.为程序编写一个字符串处理函数,用一个静态文件保存,在需要处理中文字符的JSP页面中包含它,
<%!
public String codeToString(String str)
{ ......
解决jsp或serverlet 不能解析multipart/form-data 类型的表单域的问题
10 6月 2008
Situation:
Javax.servlet.HttpServletRequest.getParameter(String) returns null when the ContentType is multipart/form-data
Solutions:
Solution A:
1. download http://www.servlets.com/cos/index.html
2. invoke getPara ......