⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 servlet.htm

📁 一个不错JSP入门教程.
💻 HTM
字号:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Servlet汉字问题解决办法&nbsp;&nbsp; 
Servlet汉字问题解决办法</title>
</head>

<body>

<p><span lang="EN-US" style="font-family:&quot;\000B&#12;&quot;">Servlet</span><span style="mso-ascii-font-family:&quot;\000B&#12;&quot;;mso-hansi-font-family:&quot;\000B&#12;&quot;">汉字问题解决办法</span><span lang="EN-US" style="font-family:&quot;\000B&#12;&quot;"><br>
<br>
<br>
Servlet</span><span style="mso-ascii-font-family:&quot;\000B&#12;&quot;;mso-hansi-font-family:
&quot;\000B&#12;&quot;">汉字问题解决办法。</span><span lang="EN-US" style="font-family:&quot;\000B&#12;&quot;"><br>
//</span><span style="mso-ascii-font-family:&quot;\000B&#12;&quot;;mso-hansi-font-family:
&quot;\000B&#12;&quot;">要在</span><span lang="EN-US" style="font-family:&quot;\000B&#12;&quot;">Linux</span><span style="mso-ascii-font-family:&quot;\000B&#12;&quot;;mso-hansi-font-family:&quot;\000B&#12;&quot;">上编译,</span><span lang="EN-US" style="font-family:&quot;\000B&#12;&quot;">JDK1.2,JSWDK1.0.1,<br>
//</span><span style="mso-ascii-font-family:&quot;\000B&#12;&quot;;mso-hansi-font-family:
&quot;\000B&#12;&quot;">时区</span><span lang="EN-US" style="font-family:&quot;\000B&#12;&quot;"> 
US-EAST<br>
<br>
import java.lang.*;<br>
import java.io.*;<br>
import javax.servlet.*;<br>
import javax.servlet.http.*;<br>
import java.sql.*;<br>
import java.util.*;<br>
<br>
public class IsItWorking extends HttpServlet {<br>
<br>
public static final String TITLE = &quot;</span><span style="mso-ascii-font-family:
&quot;\000B&#12;&quot;;mso-hansi-font-family:&quot;\000B&#12;&quot;">我们来测试</span><span lang="EN-US" style="font-family:&quot;\000B&#12;&quot;"> 
okokokok!!!!&quot;;<br>
private static Connection conn = null;<br>
<br>
String native2unicode(String s)<br>
{<br>
if(s==null || s.length()==0)<br>
{<br>
return null;<br>
}<br>
<br>
byte [] buffer = new byte[s.length()];<br>
<br>
for(int i=0;i&lt;s.length();i++)<br>
{<br>
buffer[i] = (byte)s.charAt(i);<br>
}<br>
<br>
return new String(buffer);<br>
}<br>
<br>
String unicode2native(String s)<br>
{<br>
if(s==null || s.length()==0)<br>
{<br>
return null;<br>
}<br>
<br>
char [] buffer = new char[s.length() * 2];<br>
<br>
char c;<br>
int j=0;<br>
for(int i=0;i&lt;s.length();i++)<br>
{<br>
if(s.charAt(i)&gt;=0x100)<br>
{<br>
c = s.charAt(i);<br>
byte [] buf = (&quot;&quot;+c).getBytes();<br>
buffer[j++] = (char)buf[0];<br>
buffer[j++] = (char)buf[1];<br>
}<br>
else<br>
{<br>
buffer[j++] = s.charAt(i);<br>
}<br>
}<br>
<br>
return new String(buffer,0,j);<br>
}<br>
<br>
public void service (HttpServletRequest request, HttpServletResponse response)<br>
throws ServletException, IOException<br>
{<br>
response.setContentType(&quot;text/html&quot;);<br>
ServletOutputStream out = response.getOutputStream();<br>
try<br>
{<br>
Class.forName (&quot;oracle.jdbc.driver.OracleDriver&quot;);<br>
}<br>
catch ( Exception e )<br>
{<br>
out.println(&quot;Could not establish connection.&quot;);<br>
}<br>
<br>
out.println(&quot;Success Oracle Driver JJJJJJJJJJ&lt;BR&gt;\n&quot;);<br>
<br>
out.println(TITLE);<br>
<br>
byte [] by = TITLE.getBytes(&quot;GB2312&quot;);<br>
String unicode = new String(by,&quot;8859_1&quot;);<br>
<br>
out.println(unicode+&quot;&lt;BR&gt;\n&quot;);<br>
<br>
try<br>
{<br>
try<br>
{<br>
conn = DriverManager.getConnection(&quot;jdbc:oracle:thin:@192.168.0.6:1521:ORCL&quot;, 
&quot;expert&quot;,&quot;expert&quot;);<br>
}<br>
catch(SQLException e)<br>
{<br>
out.println(&quot;Connect Error&lt;BR&gt;\n&quot;);<br>
}<br>
<br>
out.println(&quot;conn successfully&quot;);<br>
<br>
Statement stmt = null;<br>
try<br>
{<br>
stmt = conn.createStatement ();<br>
}<br>
catch(SQLException e)<br>
{<br>
out.println(&quot;STMT Error&lt;BR&gt;\n&quot;);<br>
}<br>
<br>
ResultSet rset;<br>
try<br>
{<br>
//rset = stmt.executeQuery (&quot;select modulename from modmethodinter&quot;);<br>
/*<br>
//SQL </span><span style="mso-ascii-font-family:&quot;\000B&#12;&quot;;mso-hansi-font-family:
&quot;\000B&#12;&quot;">语句嵌入汉字处理方法。</span><span lang="EN-US" style="font-family:&quot;\000B&#12;&quot;"><br>
String szSQL = &quot;insert into test values('</span><span style="mso-ascii-font-family:
&quot;\000B&#12;&quot;;mso-hansi-font-family:&quot;\000B&#12;&quot;">测试</span><span lang="EN-US" style="font-family:&quot;\000B&#12;&quot;">')&quot;;<br>
<br>
String szTemp;// = unicode2native(szSQL);<br>
<br>
byte [] b = szSQL.getBytes(&quot;8859_1&quot;);<br>
<br>
szTemp = new String(b,&quot;GB2312&quot;);<br>
*/<br>
<br>
String szSQL = &quot;select name from test&quot;;<br>
rset = stmt.executeQuery (szSQL);<br>
<br>
String szOut;<br>
String szTemp;<br>
<br>
while(rset.next())<br>
{<br>
szTemp = rset.getString(&quot;name&quot;);<br>
byte [] b = szTemp.getBytes(&quot;GB2312&quot;);<br>
szOut = new String(b,&quot;8859_1&quot;);<br>
out.println(szOut+&quot;&lt;BR&gt;\n&quot;);<br>
}<br>
rset.close();<br>
<br>
}<br>
catch(SQLException e)<br>
{<br>
out.println(&quot;SQL Execute Error&lt;BR&gt;\n&quot;);<br>
stmt.close();<br>
conn.close();<br>
return;<br>
}<br>
<br>
stmt.close();<br>
conn.close();<br>
<br>
out.println(&quot;SQL Execute Successfully&lt;BR&gt;\n&quot;);<br>
}<br>
catch(Exception e)<br>
{<br>
}<br>
<br>
/*<br>
// set content type and other response header fields first<br>
response.setContentType(&quot;text/html&quot;);<br>
<br>
ServletOutputStream out_put = response.getOutputStream();<br>
OutputStreamWriter ow = new OutputStreamWriter(out_put,&quot;8859_1&quot;);<br>
<br>
try<br>
{<br>
// byte [] b = TITLE.getBytes(&quot;GB2312&quot;);<br>
// String unicode = new String(b,&quot;8859_1&quot;);<br>
//NT out.println(unicode);<br>
//Linux<br>
ow.write(TITLE);<br>
ow.close();<br>
}<br>
catch( UnsupportedEncodingException e)<br>
{<br>
out_put.println(&quot;Error!&quot;);<br>
}<br>
// write the data<br>
//stockDb db = new stockDb();<br>
*/<br>
}<br>
public void doGet ( HttpServletRequest request, HttpServletResponse response)<br>
throws ServletException, IOException<br>
{<br>
<br>
response.setContentType(&quot;text/html&quot;);<br>
ServletOutputStream out = response.getOutputStream();<br>
<br>
out.println(&quot;Hello World&quot;);<br>
<br>
try<br>
{<br>
Class.forName (&quot;oracle.jdbc.driver.OracleDriver&quot;);<br>
}<br>
catch ( Exception e )<br>
{<br>
out.println(&quot;Could not establish connection.&quot;);<br>
}<br>
<br>
out.println(&quot;Success Oracle Driver&lt;BR&gt;\n&quot;);<br>
<br>
try<br>
{<br>
conn = DriverManager.getConnection(&quot;jdbc:oracle:thin:@192.168.0.6:1521:ORCL&quot;, 
&quot;expert&quot;,&quot;expert&quot;);<br>
<br>
out.println(&quot;conn successfully&quot;);<br>
<br>
Statement stmt = conn.createStatement ();<br>
<br>
// Select the ENAME column from the EMP table<br>
ResultSet rset = stmt.executeQuery (&quot;insert into test values('</span><span style="mso-ascii-font-family:&quot;\000B&#12;&quot;;mso-hansi-font-family:&quot;\000B&#12;&quot;">测试</span><span lang="EN-US" style="font-family:&quot;\000B&#12;&quot;">')&quot;);<br>
<br>
/*<br>
while(rset.next())<br>
{<br>
out.println(&quot;TEST&quot;);//(rset.getBinaryStream(1));<br>
}<br>
*/<br>
rset.close();<br>
stmt.close();<br>
conn.close();<br>
}<br>
catch(Exception e)<br>
{<br>
}<br>
<br>
}//doGet<br>
}<br>
<br>
<br>
<br>
Documentation is like sex. When it is good, it is very very good. When it is 
bad, it is better than nothing.<br>
-- Bruce Perence <o:p>
</o:p>
</span></p>
<p class="MsoNormal"><span lang="EN-US">&nbsp;<o:p>
</o:p>
</span></p>

</body>

</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -