中文乱码

来源:互联网 发布:svn linux 钩子脚本 编辑:程序博客网 时间:2024/04/19 05:40

1.jsp从页面输入到服务器打印出来的错误。

答案:因为我是用的是jspsmartload ,因此所在的form表单必须是

<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">


2.数据库乱码

答案:jsp页面与数据乱码改成一样的编码,并且数据库连接那也要设置编码格式

String dbUrl="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8";


3.数据库条件查询:带变量的

 db.excuteQuery("select * from problem where Problem_id =" + p_id2);

错误的格式: db.excuteQuery("select * from problem where Problem_id = + p_id2“);

或者db.excuteQuery("select * from problem where Problem_id =‘ p_id2’);


4.打印超链接可以带到下一页的一个值

out.println("<a href=\"/news/card/xianshi.jsp?Problem_id=" + db.getString("Problem_id") + "\">[查看]</a>");

xianshi.jsp 可以通过        String p_id1 = request.getParameter("Problem_id");得到该值

原创粉丝点击