一个JSP文件处理登陆,里面用到了一个JAVABEAN,是用来处理数据库的,代码:
(JSP里的?不用管,是JSP里乱码问题)
JAVABEAN:
package opendb;
import java.sql.*;
public class opendb
{
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:lfq_db";
Connection conn = null;
ResultSet rs = null;
public opendb()
{
try
{ Class.forName( sDBDriver );}
catch( java.lang.ClassNotFoundException e )
{ System.err.println( "opendb():"+ e.getMessage());}
}
public ResultSet executeQuery( String sql )
{
rs = null;
try
{
conn = DriverManager.getConnection( sConnStr,"damboo","123456");
Statement stmt = conn.createStatement();
rs = stmt.executeQuery( sql );
}
catch( SQLException ex )
{System.err.println( "aq.executeQuery:" + ex.getMessage());}
return rs;
}
}
JSP:
<html>
<head>
<title>????</title>
<meta http-equiv = "Content-Type" content = "text/html; charset = "gb2312">
</head>
<style type = "text/css">
<!--@import "css/jsp.css";-->
</style>
<body bgcolor = "#ffffff">
<%@ page import = "java.sql.*"%>
<%@ page import = "java.util.*"%>
<jsp:useBean id = "jspEx" scope = "page" class = "opendb.opendb"/>
<%
boolean canLogon = true;
java.util.Date nowdate = new java.util.Date();
long logonTime = nowdate.getTime();
String nickName = request.getParameter( "nickName");
byte[] tmpbyte = nickName.getBytes("ISO8895_1");
nickName = new String( tmpbyte );
String passWord = request.getParameter( "passWord");
String sql = "select* form chatuser where nickName like '" + nickName +"'";
ResultSet rs = jspEx.executeQuery( sql );
if( rs.next())
{
String id = rs.getString( "id" );
String repwd = rs.getString( "passWord").trim();
long lastTime = rs.getLong( "logonTime" );
rs.close();
if(( logonTime-lastTime)>30*24*3600*1000)
{
sql = "updata chatuser set logonTime = '"+logonTime+"',passWord =' "+passWord+"' where nickName like '"+nickName+"'";
rs = jspEx.executeQuery( sql );
}
else{ if (repwd.compareTo(passWord)!=0)
{ canLogon = false; }
else
{
sql = "updata charuser set logonTime = '"+logonTime+"'wherenickName like'"+nickName+"'";
rs = jspEx.executeQuery(sql);
}
}
}
else
{
rs.close();
sql = "insert chatuser( nickName ,passWord,logonTime)values('"+nickName+"','"+passWord+"','"+logonTime+"')";
rs = jspEx.executeQuery( sql );
}
if ( !canLogon )
{%>
?????<br>
?????<a href = "javascript:history.back()">??</a>!
<%}
else
{
int num1 = 0;
int num2 = 0;
int num3 = 0;
sql = "select id from userlist where chatRoom like 'laugh'";
rs = jspEx.executeQuery(sql);
while( rs.next()) num1++;
rs.close();
sql = "select id from userlist where chatRoom like 'classmate'";
rs = jspEx.executeQuery(sql);
while(rs.next()) num2++;
rs.close();
sql = "select id form userlist where chatRoom like 'program'";
rs = jspEx.executeQuery(sql);
while(rs.next()) num3++;
rs.close();
%>
<div align = "center">
<table width = "400" border = "0" cellspacing = "0">
<tr bgcolor = "#ff5d26">
<td colspan = "2" height = "12">
<div align = "center"> <b><font color = "#ffffff">??</font><font color = "#ffffff">??
<%= nickName%>??JSP</font></b><div>
</td>
</tr>
<tr>
<td bgcolor = "#ffd6c8">?<br>
<br>
</td>
<td bgcolor = "#ffd6c8">??????
</td>
</tr>
<tr>
<td bgcolor = "#ffd6c8">?<br>
<br>
</td>
<td bgcolor = "#ffd6c8">?????
</td>
</tr>
<tr>
<td bgcolor = "#ffd6c8">?</td>
<td bgcolor = "#ffd6c8">??????</td>
</tr>
<tr>
<td bgcolor = "#ffd6c8"> </td>
<td bgcolor = "#ffd6c8">
<form name = "form1" method "post" action + "main.jsp">
<input type = "radio" name = "chatRoom" value = "laugh" checked>
????(<%=num1%>?)<br>
<input type = "radio" name = "chatRoom" value = "classmate" >
????(<%=num1%>?)<br>
<input type = "radio" name = "chatRoom" value = "program" >
????(<%=num1%>?)<br>
<input type = "submit" name = "Submit" value= "??">
<input type = "hidden" name = "nickName" value = "<%=nickName%>">
<br>
</form>
</td>
</tr>
</table>
</div>
<%}%>
</body>
</html>
出错:
java.io.UnsupportedEncodingException: ISO8895_1 sun.io.Converters.getConverterClass(Unknown Source) sun.io.Converters.newConverter(Unknown Source) sun.io.CharToByteConverter.getConverter(Unknown Source) java.lang.StringCoding.encode(Unknown Source) java.lang.String.getBytes(Unknown Source) org.apache.jsp.Logon_jsp._jspService(Logon_jsp.java:70) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
又是毕业设计上出的问题,哪位英雄救我!!!!