<%@page contentType ="text/html;charset=GBK" %>
<%@page buffer="64kb"%>
<%@page autoFlush="true"%> <%@page import = "java.sql.*" %>
<%@page import = "java.util.*" %> <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>welcome</title>
</head>
<body >
<% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String source ="jdbc:odbc:gb_big5";
Connection con = DriverManager.getConnection (source);


Statement stmt = con.createStatement();
String sql = "SELECT gb,big5 From reflection";
ResultSet rs =stmt.executeQuery(sql);


String s1,s2;
Hashtable h1=new Hashtable();
while (rs.next())
{
s1 = rs.getString("gb");
out.println(s1);
s2 = rs.getString("big5");
h1.put(s1,s2);
}
%>
<%!String in_str ,out_str,s3,s4;%>
<%!int i;%>
<%
in_str =null;
out_str=null;
in_str = request.getParameter("gb");
StringBuffer sb = new StringBuffer();
   

 while(in_str !=null)
{



for (i=0;i< in_str.length()-1;i++)
{
s4 = null;
s3 =in_str.substring(i,i+1);
s4 = (String)h1.get(s3);
if (s4 != null) sb.append(s4);
else
sb.append(s3);
}
} out_str = sb.toString ();

rs.close();
stmt.close();
con.close();
%> <P></P> <P></P>
<P></P>
<form name="form1" method="get" action="/jsp.jsp" TARGET = _top>
<p> &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; please select :
<select name="select" size="1">
<option>gb to big5</option>
<option>big5 to gb</option>
</select>
</p>

  <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    <textarea name="gb" cols="13" rows="13"><%= in_str %></textarea>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    <input type="submit" name="Submit" value="conversion">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; 
    <textarea name="big" cols="13" rows="13"><%= out_str %></textarea>
  </p>

</form>
</body>
</html>

解决方案 »

  1.   

    java.lang.OutOfMemoryError,程序逻辑有问题啊
      

  2.   

    你为什么把import放在了body里面
    这肯定会出现逻辑问题
    一般把<%@page import = " " %>放在最前面
      

  3.   

    java.lang.OutOfMemoryError,内存溢出,你的循环有问题:
    while(in_str !=null)
    {



    for (i=0;i< in_str.length()-1;i++)
    {
    s4 = null;
    s3 =in_str.substring(i,i+1);
    s4 = (String)h1.get(s3);
    if (s4 != null) sb.append(s4);
    else
    sb.append(s3);
    }
    }
    没有跳出循环的语句,你需要在循环体内在一定条件下跳出如if(...)break;
      

  4.   

    pcliu1980(捕风) :
    你为什么把import放在了body里面
    这肯定会出现逻辑问题
    一般把<%@page import = " " %>放在最前面
    这样做还是不行.
     yshgfly(yshgfly): 我的输入的字符串是连续读入的,break不就中断后面了.
    谢谢各位,请大家断续帮忙
      

  5.   

     while(in_str !=null)
    改为
    if (in_str !=null)