小弟最近初学jsp,学习书籍是《JSP实用案例教程》 清华大学出版社,冯燕奎写的,在做一个投票系统的案例。我代码中所有的编码方式都是utf-8,包括文件编码也是utf-8。
tomcat 里的web.xml 设置的也是utf-8
- Assembly code
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <jsp-config> <jsp-property-group> <description> Special property group for JSP Configuration JSP example. </description> <display-name>JSPConfiguration</display-name> <url-pattern>*.jsp</url-pattern> <el-ignored>true</el-ignored> <page-encoding>UTF-8</page-encoding> <scripting-invalid>false</scripting-invalid> <include-prelude></include-prelude> <include-coda></include-coda> <description> Special property group for JSP Configuration JSP example. </description> <display-name>JSPConfiguration</display-name> <url-pattern>*</url-pattern> <el-ignored>true</el-ignored> <page-encoding>UTF-8</page-encoding> <scripting-invalid>false</scripting-invalid> <include-prelude></include-prelude> <include-coda></include-coda> </jsp-property-group></jsp-config> <welcome-file-list> <welcome-file>index</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
我又两个问题想请教大家。
第一个,增加项目提交form表单时中文乱码;
第二个,增加项目、删除项目之后details.jsp,admin.jsp页面需要刷新一次才能显示更改后的数据。
数据库是用书上的例子实用Access数据库,数据库连接正常,各种操作也正常。
下面是代码:
后台管理页面
admin.jsp
- Assembly code
<%@page contentType="text/html;charset=UTF-8"%><%@page language="java" import="java.sql.*"%><jsp:useBean id="connDbBean" scope="page" class="vote.VoteConn"/><script language="JavaScript"> window.location.reload();</script> <html> <head> <title>后台</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body bgcolor="#ffffff"> <div align="center"> <p><font color="#990000" size="+2"><u>调查系统维护中心</u></font></p> <% ResultSet tempRs=connDbBean.executeQuery("select id,note from vote order by id"); %> <table width="80%" border="0" cellspacing="1" cellpadding="2"> <tr> <td width="10%" class="text1" bgcolor="#99ccff"> <div align="center">序号<div> </td> <td width="80%" class="text1" bgcolor="#99ccff"> <div align="center">内容<div> </td> <td width="10%" class="text1" bgcolor="#99ccff"> <div align="center">^_^<div> </td> </tr> <% int i =1; while(tempRs.next()) {%> <tr> <td><div align="center"><%=i%></div></td> <td align="center"><%=tempRs.getString("note")%></td> <td><div align="center"><a href="delvote.jsp?id=<%=tempRs.getInt("id")%>" >删除</a></div></td> </tr> <% i=i+1; } %> <tr> <td colspan="3"> <hr width="100%" size="1"> </td> </tr> <tr> <td class="text1"><div align="center"></div> </td> <td class="text1" colspan="2"> </td> </tr> <tr> <td class="text1" colspan="3" bgcolor="#99ccff">增加项目 </td> </tr> <tr> <td class="text1" colspan="3"> <form method ="post" action="addvote.jsp"> <p>内容 <input type="text" name="note" size="50" maxlength="50"> </p> <p> <input type="submit" name="Submit" value="提交""> <input type="reset" name="Submit2" value="重置"> </p> <p> </p> </form> </td> </tr> </table> <% tempRs.close(); %> </body></html>