jsp中文乱码问题
解决办法:
第一:
1:在jsp页面加入:
<%@ page contentType="text/html; charset=gb2312" %>
2:在servlet里面:
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html; charset=gb2312");//这是重要的
3:上面的如果在不行就用如下的方法在数据入库前进行调用:
public static String UnicodeToChinese(String s){
try{
if(s==null ¦ ¦s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("ISO8859_1"),"gb2312");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}
public static String ChineseToUnicode(String s){
try{
if(s==null ¦ ¦s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("gb2312"),"ISO8859_1");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}
相关文档:
在JSP/Servlet 中主要有以下几个地方可以设置编码,pageEncoding="UTF-8"、contentType="text/html;charset=UTF -8"、request.setCharacterEncoding("UTF-8")和response.setCharacterEncoding ("UTF-8"),其中前两个只能用于JSP中,而后两个可以用于JSP和Servlet中。
1、pageEncoding="UTF-8"的作用是设置JSP编译成Servlet ......
WEB开发中经常用到上传图,在未上传之前要显示所选择的图片
可以用简单的JS 实现:
<html>
<head>
<SCRIPT language=JavaScript>
function showimg(){
var imgpeoper=form1.imgs.value;
form1.img.src=imgpeoper;
......
<%@ page contentType="text/html; charset=GB2312" %>
<%@ page errorPage="jsp3_error.jsp" %>
<%@ page import="java.util.*,java.io.*" %>
<html>
<head>
<title>
jsp综合应用
</title>
</head>
<jsp:useBean id="jsp3BeanId" scope="session" class="pan ......
不要在JSP中处理用户请求(request),也不要在JSP中嵌入控制流代码
不要将用户界面部分和业务逻辑部分混合
在JSP中尽量不要包含java代码,EL在这方面可以给我们很大帮助
将页面分为几个部分:Header,Menu,Main。。。
......