我想这么做,但是总报错,请问为什么 关于 javabean

Vicky020923 2004-04-18 11:29:43
----admin_message_list.jsp-----------

<%@ page import="java.sql.*" %>
<jsp:include page="admin_head.jsp" />
<HTML>
<HEAD>
<TITLE> 信息列表 </TITLE>
<style type="text/css">
<!--
@import url("Images/admin_right.css");
-->
</style>
</HEAD>
<BODY>
<table class=tableBorder width="90%" border="0" align="center" cellpadding="3" cellspacing="1">
<tr>
<TH class="tableHeaderText" colSpan="6" height="25">信息列表</th>
</tr>
<tr>
<td class="forumRow" width="60" height="25" nowrap><div align="center">信息编号</div></td>
<td class="forumRow"><div align="center">信息标题</div></td>
<td class="forumRow"><div align="center">信息内容</div></td>
<td class="forumRow" widht="60" nowrap><div align="center">作者</div></td>
<td class="forumRow" widht="40" nowrap><div align="center">修改</div></td>
<td class="forumRow" widht="40" nowrap><div align="center">删除</div></td>
</tr>
<jsp:useBean id="listMessage" class="com.neusoft.vicky.ConnectToDataBase" />
<%
String temp;
listMessage.connect();
String sqlString = "SELECT * FROM vicky_message ORDER BY no DESC";
ResultSet rs=listMessage.select(sqlString);
while (rs.next())
{
%>
<tr>
<td class="forumRow" nowrap><div align="center"><%=rs.getInt("no")%></div></td>
<td class="forumRow"><div align="left">
<%
temp= rs.getString("title");
// ***************************** 问题所在
temp=listMessage.decodeChar(temp); //报错
// temp = new String(temp.getBytes("GBK"),"ISO8859_1");
out.println(temp);
%>
</div></td>
<td class="forumRow"><div align="center">
<%
temp= rs.getString("content");
out.println(temp);
%>
</div></td>
<td class="forumRow" nowrap><div align="center"><%=rs.getString("send_user")%></div></td>
<td class="forumRow" widht="40" nowrap><div align="center"><a href="">修改</a></div></td>
<td class="forumRow" widht="40" nowrap><div align="center"><a href=admin_del.jsp?db=vicky_message&no=<%=rs.getInt("no")%>>删除</a></div></td>
</tr>
<%
}
listMessage.disconnect();
%>
</table>
<br />
</form>
<jsp:include page="admin_foot.jsp" />
</BODY>
</HTML>


--ConnectToDataBase.java--

package com.neusoft.vicky;

import java.sql.*;
import java.util.*;

public class ConnectToDataBase
{
private String chineseChar;
String queryString;
String error;
Connection conn=null;
Statement myStatement=null;
ResultSet rs=null;

public void connect() throws ClassNotFoundException,SQLException,Exception
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
conn=DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.7:1521:HLJUBISP","neusoft","neusoft");
}
catch (ClassNotFoundException e)
{
error="ClassNotFoundException:Could not locate DB driver.";
throw new ClassNotFoundException(error);
}
catch(SQLException e)
{
error="SQLException:Could not connect to database.";
throw new SQLException (error);
}
catch(Exception e)
{
error="Excetpion: An unknown error occurred while connecting to database";
throw new Exception(error);
}
}
public void disconnect () throws SQLException
{
try
{
if (conn!=null)
{
conn.close();
}
}
catch(SQLException e)
{
error="SQLException : Unable to close the database connection.";
throw new SQLException (error);
}
}
public ResultSet select(String myString) throws SQLException ,Exception
{
if (conn!=null)
{
try
{
queryString=encodeChar(myString);
myStatement = conn.createStatement();
rs=myStatement.executeQuery(queryString);
}
catch (SQLException e)
{
error="SQLException:Could not execute the query.";
throw new SQLException(error);
}
catch (Exception e)
{
error="an exception occured.";
throw new Exception(error);
}
return rs;
}
else
{
error="Exception : Connection to database was lost.";
throw new Exception(error);
}
}

public void insert(String myString) throws SQLException ,Exception
{
if (conn!=null)
{
try
{
queryString=encodeChar(myString);
myStatement = conn.createStatement();
rs=myStatement.executeQuery(queryString);
}
catch (SQLException e)
{
error="SQLException:Could not execute the query.";
throw new SQLException(error);
}
catch (Exception e)
{
error="an exception occured.";
throw new Exception(error);
}
}
else
{
error="Exception : Connection to database was lost.";
throw new Exception(error);
}
}

public void delete(String myString) throws SQLException ,Exception
{
insert(myString);
}


public void update(String myString) throws SQLException ,Exception
{
insert(myString);
}
//字符转换函数
public String encodeChar(String myString)
{
try
{
if(myString==null)
{
myString="";
}
else
{
myString = new String(myString.getBytes("ISO8859_1"), "GBK");
}
return myString;
}
catch(Exception e)
{
return "";
}
}




public String decodeChar(String myString)
{
try
{
if(myString==null)
{
myString="";
}
else
{
myString = new String(myString.getBytes("GBK"),"ISO-8859-1" );
}
return myString;
}
catch(Exception e)
{
return "";
}
}
};




========================================


<%
temp= rs.getString("title");
// ***************************** 问题所在
temp=listMessage.decodeChar(temp); //报错
// temp = new String(temp.getBytes("GBK"),"ISO8859_1");
out.println(temp);
%>


temp=listMessage.decodeChar(temp); //报错

但是

// temp = new String(temp.getBytes("GBK"),"ISO8859_1");

却能通过




请高手指教.谢谢!!!!!!!
...全文
61 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Vicky020923 2004-04-19
  • 打赏
  • 举报
回复
重起下机器 解决了

程序本身没问题

感谢关注
紫罗兰Cherry 2004-04-19
  • 打赏
  • 举报
回复
你试着在jsp加判断看看,
<%
temp= rs.getString("title");
if(temp == null || temp.equals("")
{
temp=listMessage.decodeChar(temp);
// temp = new String(temp.getBytes("GBK"),"ISO8859_1");
out.println(temp);
}
%>


其他的应该没问题啊。
Vicky020923 2004-04-19
  • 打赏
  • 举报
回复
Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: com.neusoft.vicky.ConnectToDataBase.decodeChar(Ljava/lang/String;)Ljava/lang/String;
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
org.apache.jsp.admin_005fmessage_005flist_jsp._jspService(admin_005fmessage_005flist_jsp.java:138)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


root cause

java.lang.NoSuchMethodError: com.neusoft.vicky.ConnectToDataBase.decodeChar(Ljava/lang/String;)Ljava/lang/String;
org.apache.jsp.admin_005fmessage_005flist_jsp._jspService(admin_005fmessage_005flist_jsp.java:98)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


note The full stack trace of the root cause is available in the Tomcat logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.0.19
sagittarius1979 2004-04-19
  • 打赏
  • 举报
回复
看程序好像没有错误,具体报什么错误。。。
Vicky020923 2004-04-18
  • 打赏
  • 举报
回复
只看
public String decodeChar(String myString)


<%
temp= rs.getString("title");
// ***************************** 问题所在
temp=listMessage.decodeChar(temp); //报错
// temp = new String(temp.getBytes("GBK"),"ISO8859_1");
out.println(temp);
%>

这两部分就可以了.

别的地方应该没问题

高手帮忙

81,090

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧