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;
}
}
相关文档:
很多例如登录或者注销登录的地方需要使用到Cookie,今天学到在JSP中如何操作Cookie分享下
4.Cookie类常用的方法
1.setValue()/getValue() —>获取cookie对象的值。
2.getName()—>获取cookie对象的名称,循环的时候可以有选择的使用Cookie
3.setMaxAge()/getMaxAge()—>设置或获取cookie对象有 ......
WEB开发中经常用到上传图,在未上传之前要显示所选择的图片
可以用简单的JS 实现:
<html>
<head>
<SCRIPT language=JavaScript>
function showimg(){
var imgpeoper=form1.imgs.value;
form1.img.src=imgpeoper;
......
简单示例
JSP页面中,我们经常有引用各种图片等资源,例如下面的jsp片段中
<div class="main">
<a href="http://www.sina.com.cn/abc.htm">
<strong>我的档案</strong>
&nbs ......
不要在JSP中处理用户请求(request),也不要在JSP中嵌入控制流代码
不要将用户界面部分和业务逻辑部分混合
在JSP中尽量不要包含java代码,EL在这方面可以给我们很大帮助
将页面分为几个部分:Header,Menu,Main。。。
......
1.调用JSP页面显示乱码
通过浏览器调用JSP页面,在客户端浏览器中所有的中文内容出现乱码。
solution:
首先确认本JSP在编辑器中保存时,使用的是GBK的编码格式,然后在JSP页面的开始部分添加 <%@ pageEncoding="GBK" %>就可以解决中文乱码问题。
2.调用Servlet页面显示乱码
通过浏览器调用Servlet,Servlet在浏 ......