??xml version="1.0" encoding="utf-8" standalone="yes"?>成人77777,91美女视频在线,精品福利一区http://www.aygfsteel.com/qclass/category/9498.html解放思想Q实事求?/description>zh-cnFri, 02 Mar 2007 06:30:48 GMTFri, 02 Mar 2007 06:30:48 GMT60在JSP里面昄由数据库d出来的图片数?/title><link>http://www.aygfsteel.com/qclass/articles/51911.html</link><dc:creator>QpdcR方法、变量…?/dc:creator><author>QpdcR方法、变量…?/author><pubDate>Sat, 10 Jun 2006 15:55:00 GMT</pubDate><guid>http://www.aygfsteel.com/qclass/articles/51911.html</guid><wfw:comment>http://www.aygfsteel.com/qclass/comments/51911.html</wfw:comment><comments>http://www.aygfsteel.com/qclass/articles/51911.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/qclass/comments/commentRss/51911.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/qclass/services/trackbacks/51911.html</trackback:ping><description><![CDATA[ <p>环境mysql+tomcat:</p> <p><1>先在mysql下徏立如下的table. qinsert囑փ.</p> <p>mysql.sql文g如下:</p> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> <span style="COLOR: #0000ff">CREATE</span> <span style="COLOR: #000000"> </span> <span style="COLOR: #0000ff">TABLE</span> <span style="COLOR: #000000"> photo (<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />photo_no </span> <span style="FONT-WEIGHT: bold; COLOR: #000000">int</span> <span style="COLOR: #000000">(</span> <span style="FONT-WEIGHT: bold; COLOR: #800000">6</span> <span style="COLOR: #000000">) unsigned </span> <span style="COLOR: #808080">NOT</span> <span style="COLOR: #000000"> </span> <span style="COLOR: #0000ff">NULL</span> <span style="COLOR: #000000"> auto_increment,<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /></span> <span style="FONT-WEIGHT: bold; COLOR: #000000">image</span> <span style="COLOR: #000000"> blob,<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /></span> <span style="COLOR: #0000ff">PRIMARY</span> <span style="COLOR: #000000"> </span> <span style="COLOR: #0000ff">KEY</span> <span style="COLOR: #000000"> (`photo_no`)<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />) </span> </div> <p> <br /><2>把show.jsp攑֜tomcat的Q意目录下. show.jsp作用:从数据库中读出blob,q生image/jpg.</p> <p>show.jsp文g如下:</p> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> <span style="COLOR: #000000"><%</span> <span style="COLOR: #000000">@ page contentType</span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">text/html; charset=gbk</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000"> </span> <span style="COLOR: #000000">%></span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #000000"><%</span> <span style="COLOR: #000000">@ page </span> <span style="COLOR: #0000ff">import</span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">java.io.*</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">%></span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #000000"><%</span> <span style="COLOR: #000000">@ page </span> <span style="COLOR: #0000ff">import</span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">java.sql.*, javax.sql.*</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000"> </span> <span style="COLOR: #000000">%></span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #000000"><%</span> <span style="COLOR: #000000">@ page </span> <span style="COLOR: #0000ff">import</span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">java.util.*</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">%></span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #000000"><%</span> <span style="COLOR: #000000">@ page </span> <span style="COLOR: #0000ff">import</span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">java.math.*</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">%></span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #000000"><%</span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> String photo_no </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> request.getParameter(</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">photo_no</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">);<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">mysqlq接 </span> <span style="COLOR: #008000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #000000"> Class.forName(</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">com.mysql.jdbc.Driver</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">).newInstance();<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> String URL</span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">jdbc:mysql://localhost:3306/job?user=root&password=111111</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">;<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> Connection con </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> DriverManager.getConnection(URL);<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">oracleq接 <br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">String URL="jdbc:oracle:thin@localhost:1521:orcl2";<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">user="system";<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">password="manager";<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">Connection con = DriverManager.getConnection(URL,user,password);</span> <span style="COLOR: #008000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> <br /> <img id="Codehighlighter1_622_1165_Open_Image" onclick="this.style.display='none'; Codehighlighter1_622_1165_Open_Text.style.display='none'; Codehighlighter1_622_1165_Closed_Image.style.display='inline'; Codehighlighter1_622_1165_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /> <img id="Codehighlighter1_622_1165_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_622_1165_Closed_Text.style.display='none'; Codehighlighter1_622_1165_Open_Image.style.display='inline'; Codehighlighter1_622_1165_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /> </span> <span style="COLOR: #0000ff">try</span> <span id="Codehighlighter1_622_1165_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"> <img src="http://www.aygfsteel.com/images/dot.gif" /> </span> <span id="Codehighlighter1_622_1165_Open_Text"> <span style="COLOR: #000000">{<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000"> 准备语句执行对象</span> <span style="COLOR: #008000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span> <span style="COLOR: #000000">  Statement stmt </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> con.createStatement();<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />  String sql </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> </span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000"> SELECT * FROM PHOTO WHERE photo_no = </span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">+</span> <span style="COLOR: #000000"> photo_no;<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />  ResultSet rs </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> stmt.executeQuery(sql);<br /><img id="Codehighlighter1_806_1086_Open_Image" onclick="this.style.display='none'; Codehighlighter1_806_1086_Open_Text.style.display='none'; Codehighlighter1_806_1086_Closed_Image.style.display='inline'; Codehighlighter1_806_1086_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_806_1086_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_806_1086_Closed_Text.style.display='none'; Codehighlighter1_806_1086_Open_Image.style.display='inline'; Codehighlighter1_806_1086_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />  </span> <span style="COLOR: #0000ff">if</span> <span style="COLOR: #000000"> (rs.next()) </span> <span id="Codehighlighter1_806_1086_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"> <img src="http://www.aygfsteel.com/images/dot.gif" /> </span> <span id="Codehighlighter1_806_1086_Open_Text"> <span style="COLOR: #000000">{<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />   Blob b </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> rs.getBlob(</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">photo_image</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">);<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />   </span> <span style="COLOR: #0000ff">long</span> <span style="COLOR: #000000"> size </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> b.length();<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />   </span> <span style="COLOR: #008000">//</span> <span style="COLOR: #008000">out.print(size);</span> <span style="COLOR: #008000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span> <span style="COLOR: #000000">   </span> <span style="COLOR: #0000ff">byte</span> <span style="COLOR: #000000">[] bs </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> b.getBytes(</span> <span style="COLOR: #000000">1</span> <span style="COLOR: #000000">, (</span> <span style="COLOR: #0000ff">int</span> <span style="COLOR: #000000">)size);<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />   response.setContentType(</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">image/jpeg</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">); <br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />   OutputStream outs </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> response.getOutputStream(); <br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />   outs.write(bs);<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />   outs.flush();<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />   rs.close(); <br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />  }</span> </span> <span style="COLOR: #000000"> <br /> <img id="Codehighlighter1_1095_1162_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1095_1162_Open_Text.style.display='none'; Codehighlighter1_1095_1162_Closed_Image.style.display='inline'; Codehighlighter1_1095_1162_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /> <img id="Codehighlighter1_1095_1162_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1095_1162_Closed_Text.style.display='none'; Codehighlighter1_1095_1162_Open_Image.style.display='inline'; Codehighlighter1_1095_1162_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />  </span> <span style="COLOR: #0000ff">else</span> <span style="COLOR: #000000"> </span> <span id="Codehighlighter1_1095_1162_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"> <img src="http://www.aygfsteel.com/images/dot.gif" /> </span> <span id="Codehighlighter1_1095_1162_Open_Text"> <span style="COLOR: #000000">{<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />   rs.close();<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />   response.sendRedirect(</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">./images/error.gif</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">);<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />  }</span> </span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" /> }</span> </span> <span style="COLOR: #000000"> <br /> <img id="Codehighlighter1_1175_1193_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1175_1193_Open_Text.style.display='none'; Codehighlighter1_1175_1193_Closed_Image.style.display='inline'; Codehighlighter1_1175_1193_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /> <img id="Codehighlighter1_1175_1193_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1175_1193_Closed_Text.style.display='none'; Codehighlighter1_1175_1193_Open_Image.style.display='inline'; Codehighlighter1_1175_1193_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /> </span> <span style="COLOR: #0000ff">finally</span> <span id="Codehighlighter1_1175_1193_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"> <img src="http://www.aygfsteel.com/images/dot.gif" /> </span> <span id="Codehighlighter1_1175_1193_Open_Text"> <span style="COLOR: #000000">{<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />  con.close();<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" /> }</span> </span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #000000">%></span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> </div> <p> <br /><3>把如下文件放在show.jsp的同一目录?</p> <p>index.html文g如下:</p> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> <span style="COLOR: #0000ff"><</span> <span style="COLOR: #800000">HTML</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff"><</span> <span style="COLOR: #800000">HEAD</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff"><</span> <span style="COLOR: #800000">TITLE</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> 囑փ试 </span> <span style="COLOR: #0000ff"></</span> <span style="COLOR: #800000">TITLE</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff"></</span> <span style="COLOR: #800000">HEAD</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff"><</span> <span style="COLOR: #800000">BODY</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff"><</span> <span style="COLOR: #800000">TABLE</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff"><</span> <span style="COLOR: #800000">TR</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff"><</span> <span style="COLOR: #800000">TD</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000">囑փ试</span> <span style="COLOR: #0000ff"></</span> <span style="COLOR: #800000">TD</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff"></</span> <span style="COLOR: #800000">TR</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff"><</span> <span style="COLOR: #800000">TR</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff"><</span> <span style="COLOR: #800000">TD</span> <span style="COLOR: #0000ff">><</span> <span style="COLOR: #800000">img </span> <span style="COLOR: #ff0000">src</span> <span style="COLOR: #0000ff">="show.jsp?photo_no=2"</span> <span style="COLOR: #0000ff">></</span> <span style="COLOR: #800000">TD</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff"></</span> <span style="COLOR: #800000">TR</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff"></</span> <span style="COLOR: #800000">TABLE</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff"></</span> <span style="COLOR: #800000">BODY</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> <span style="COLOR: #0000ff"></</span> <span style="COLOR: #800000">HTML</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /> </span> </div> <img src ="http://www.aygfsteel.com/qclass/aggbug/51911.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/qclass/" target="_blank">QpdcR方法、变量…?/a> 2006-06-10 23:55 <a href="http://www.aygfsteel.com/qclass/articles/51911.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JSP常用问答http://www.aygfsteel.com/qclass/articles/45115.htmlQpdcR方法、变量…?/dc:creator>QpdcR方法、变量…?/author>Mon, 08 May 2006 15:57:00 GMThttp://www.aygfsteel.com/qclass/articles/45115.htmlhttp://www.aygfsteel.com/qclass/comments/45115.htmlhttp://www.aygfsteel.com/qclass/articles/45115.html#Feedback0http://www.aygfsteel.com/qclass/comments/commentRss/45115.htmlhttp://www.aygfsteel.com/qclass/services/trackbacks/45115.html JSP常用问答

1、如何؜合用Jsp和SSI #include?
在JSP中可以用如下方式包含纯HTMLQ?
<!--#include file="data.inc"-->
但是如果data.inc中包含JSP CODE Q我们可以用:
<%@include file="data.inc"%>


2、如何执行一个线E安全的JSP?
只需增加如下指o
<%@ page isThreadSafe="false" %>


3、JSP如何处理HTML FORM中的数据?
通过内置的request对象卛_Q如下:
<%
String item = request.getParameter("item");
int howMany = new Integer(request.getParameter("units")).intValue();
%>


4、在JSP如何包含一个静态文?
静态包含如下:<%@ include file="copyright.html" %>
动态包含如下:<jsp:include page="copyright.html" flush="true"/>


5、在JSP中如何用注?
主要有四中方法:
1?lt;%-- ?--%>
2?/
3?**?*/
4?lt;!--?->


6、在JSP中如何执行浏览重定向?
使用如下方式卛_Qresponse.sendRedirect("也能物理地改变HTTP HEADER属性,如下Q?
<%
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
String newLocn="/newpath/index.html";
response.setHeader("Location",newLocn);
%>


7、如何防止在JSP或SERVLET中的输出不被BROWSER保存在CACHE?
把如下脚本加入到JSP文g的开始即可:
<%
response.setHeader("Cache-Control","no-store"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
%>


8、在JSP中如何设|COOKIE?
COOKIE是作为HTTP HEADER的一部分被发送的Q如下方法即可设|:
<%
Cookie mycookie = new Cookie("aName","aValue");
response.addCookie(mycookie);
%>


9、在JSP中如何删除一个COOKIE?
<%
Cookie killMyCookie = new Cookie("mycookie", null);
killMyCookie.setMaxAge(0);
killMyCookie.setPath("/");
response.addCookie(killMyCookie);
%>


10、在一个JSP的请求处理中如何停止JSP的执?
如下例:
<%
if (request.getParameter("wen") != null) {
// do something
} else {
return;
}
%>


11、在JSP中如何定义方?
你可以定义方法,但是你不能直接访问JSP的内|对象,而是通过参数的方法传递。如下:
<%!
public String howBadFrom(HttpServletRequest req) {
HttpSession ses = req.getSession();
...
return req.getRemoteHost();
}
%>
<%
out.print("in general,lao lee is not baddie ");
%>
<%= howBadFrom(request) %>


12、如果BROWSER已关闭了COOKIESQ在JSP中我如何打开SESSION来跟t?
使用URL重写卛_Q如下:
hello1.jsp
<%@ page session="true" %>
<%
Integer num = new Integer(100);
session.putValue("num",num);
String url =response.encodeURL("hello2.jsp");
%>
<a href=<%=url%>>hello2.jsp</a>

hello2.jsp
<%@ page session="true" %>
<%
Integer i= (Integer )session.getValue("num");
out.println("Num value in session is "+i.intValue());
%>


13、在JSP中能发送EMAIL?
可以使用SUN的专用包Qsun.net.smtp包。如下脚本用SmtpClientcd送EMAIL?
<%@ page import="sun.net.smtp.SmtpClient, java.io.*" %>
<%
String from="
ybwen@sina.com";
String to="hewenjun@yeah.net, lei@who.com.cn";
try{
SmtpClient client = new SmtpClient("mail.xxxxx.xxx");
client.from(from);
client.to(to);
PrintStream message = client.startMessage();
message.println("To: " + to);
message.println("Subject: Sending email from JSP!");
message.println("This was sent from a JSP page!");
message.println();
message.println("Cool! :-)");
message.println();
message.println("Good Boy");
message.println("Im in genius.com");
message.println();
client.closeServer();
}
catch (IOException e){
System.out.println("ERROR SENDING EMAIL:"+e);
}
%>


14、在SERVLET中我能调用一个JSP错误吗
当然没问题,如下展示了如何在一个SERVLET控制逻辑单元内调用一个JSP错误面?
protected void sendErrorRedirect(HttpServletRequest request,
HttpServletResponse response, String errorPageURL,
Throwable e)
throws ServletException, IOException {
request.setAttribute ("javax.servlet.jsp.jspException", e);
getServletConfig().getServletContext().
getRequestDispatcher(errorPageURL).forward(request,
response);
}

public void doPost(HttpServletRequest request,HttpServletResponse response) {
try {
// do something
} catch (Exception ex) {
try {
sendErrorRedirect(request,response,"/jsp/MyErrorPage.jsp",ex);
} catch (Exception e) {
e.printStackTrace();
}
}
}


15、JSP和APPLET如何通讯
JSP如何与EJB SessionBean通讯
下面的代码段作了很好的示?
<%@ page import="javax.naming.*, javax.rmi.PortableRemoteObject,
foo.AccountHome, foo.Account" %>
<%!
//定义一个对SessionBeanHome接口实例的全局引用
AccountHome accHome=null;

public void jspInit() {
//获得Home接口实例
InitialContext cntxt = new InitialContext( );
Object ref= cntxt.lookup("java:comp/env/ejb/AccountEJB");
accHome = (AccountHome)PortableRemoteObject.narrow(ref,AccountHome.class);
}
%>
<%
//实例化SessionBean
Account acct = accHome.create();
//调用q程Ҏ
acct.doWhatever(...);
// 如此{等
%>


16、当我用一个结果集Ӟ如何防止字段?null"的字域显C在我的HTML输入文本域中?
可以定义一个简单的函数来达到目的,如下Q?
<%!
String blanknull(String s) {
return (s == null) ? "" : s;
}
%>

然后在JSP的FORM中,可以q样使用
<input type="text" name="shoesize" value="<%=blanknull(shoesize)%>">


17、如何中SERVLET或JSP下蝲一个文Ӟ如:binary,text,executable)Q?
现提供两个解x案:
AQ用HTTPQ?
BQ在Servlet中,通过讄ContentType和用java.io包的Stream{类可作?例如Q?
response.setContentType("application/x-msword");
然后惌出缓冲中写一些东东即可?

18、用useBean标志初始化BEAN时如何接受初始化参数
使用如下两标{֍可:
<jsp:getProperty name="wenBean" property="someProperty"/>
<jsp:setProperty name="wenBean" property="someProperty" value="someValue"/>

19、用JSP如何获得客户览器的信息Q?
使用request.getHeader(String)卛_


20、能象调用子E序一栯用JSP吗?
当然可以Q用<jsp:include page="relativeURL" flush="true"/>


21、当我重~译我的JSP使用的一个类后,Z么JVMl箋使用我的老CLASSQ?


<%@include file="abc.jsp"%>?lt;jsp:include page="abc.jsp"/>之间的差别?
前一个ؓ静态包含,而后一个ؓ动态包?


22、JSP的缺点?
1。对JAVAE序q行调试没有好东?
2。因大多数的servlet引擎不支持connection pooling
3。Servlet引擎没有标准
4。JSP与其它脚本语a的交?


23、JSP能进行递归调用吗?
当然可以,如对form的提交给本页


34、如何实现JSP的国际化Q?
为各U版本提供resource bundles属性文件即?

25、在JSP中如何写文本文gQ?
使用PrintWriter对象Q如Q?
<%@ page import="java.io.*" %>
<%
String str = "print me";
String nameOfTextFile = "/usr/anil/imp.txt";
try {
PrintWriter pw = new PrintWriter(new FileOutputStream(nameOfTextFile));
pw.println(str);
pw.close();
} catch(IOException e) {
out.println(e.getMessage());
}
%>


26、如何在JSP中包括绝对\径文Ӟ
使用URLConnection卛_?


27、在servlets和JSP之间能共享session对象吗?
当然可以Q?
HttpSession session = request.getSession(true);
session.putValue("variable","value");


28、JavaScript的变量能复制到JSP的SESSION中吗Q?


29、如何设|cookie在某一旉后过期?
用Cookie.setMaxAge(int)


30、如何获得当前的sessions敎ͼ
可以使用HttpSessionBindingListeners来跟t?


31、能讄一些代码在我所有的JSP文g之上q行Q如果可以,能共享吗Q?
当然可以,可以Z的JSP文g定义一个别?/jsp/=ybwen.genius.myPreprocessingServlet,而以/jsp/为前~的文件可以?


32、对一个JSP,如果多个客户端同时请求它Q同步可能吗Q?
在jsp:useBean语法中用beanName有何好处Q?
beanName使用Beans.instantiate()初始化Bean


33、当我?lt;jsp:forward>Ӟ在浏览器的地址栏没有改变?
使用response.sendRedirect("newURL")


34、如何{换JSP 0.9版本的文件到JSP1.1?
可用sed/awk卛_


35、用JSP能设|HTML FORM中输入域的焦点,不用JavaScript?
没办?


36、用JSPq接到数据库q接~冲池的最好方法是什么?
1.使用JDBC2?中带有此服务的Driver
2.使用提供有此服务的Application server
3.自己?/p>

]]>
从URL获取文g保存到本地的代码http://www.aygfsteel.com/qclass/articles/39210.htmlQpdcR方法、变量…?/dc:creator>QpdcR方法、变量…?/author>Tue, 04 Apr 2006 09:09:00 GMThttp://www.aygfsteel.com/qclass/articles/39210.htmlhttp://www.aygfsteel.com/qclass/comments/39210.htmlhttp://www.aygfsteel.com/qclass/articles/39210.html#Feedback0http://www.aygfsteel.com/qclass/comments/commentRss/39210.htmlhttp://www.aygfsteel.com/qclass/services/trackbacks/39210.html <% @page  import = " java.net.*,java.io.* " %>
<%!
  
public   boolean  saveUrlAs(String photoUrl, String fileName)  {
// 此方法只能用户HTTP协议
     try   {
      URL url 
=   new  URL(photoUrl);
      HttpURLConnection connection 
=  (HttpURLConnection) url.openConnection();
      DataInputStream in 
=   new  DataInputStream(connection.getInputStream());
      DataOutputStream out 
=   new  DataOutputStream( new  FileOutputStream(fileName));
      
byte [] buffer  =   new   byte [ 4096 ];
      
int  count  =   0 ;
      
while  ((count  =  in.read(buffer))  >   0 {
        out.write(buffer, 
0 , count);
      }

      out.close();
      in.close();
      
return   true ;
    }

    
catch  (Exception e)  {
      
return   false ;
    }

  }

 
public  String getDocumentAt(String urlString)  {
// 此方法兼容HTTP和FTP协议
    StringBuffer document  =   new  StringBuffer();
    
try   {
      URL url 
=   new  URL(urlString);
      URLConnection conn 
=  url.openConnection();
      BufferedReader reader 
=   new  BufferedReader( new  InputStreamReader(conn.
          getInputStream()));
      String line 
=   null ;
      
while  ( (line  =  reader.readLine())  !=   null {
        document.append(line 
+   " \n " );
      }

      reader.close();
    }

    
catch  (MalformedURLException e)  {
      System.out.println(
" Unable to connect to URL:  "   +  urlString);
    }

    
catch  (IOException e)  {
      System.out.println(
" IOException when connecting to URL:  "   +  urlString);
    }

    
return  document.toString();
  }

%>
<%
//
  String photoUrl  =   " http://ad4.sina.com.cn/200601/12/43932_750450.jpg " ;
  String fileName 
=  photoUrl.substring(photoUrl.lastIndexOf( " / " ));
  String filePath 
=   " d:/ghost/ " ;
  
boolean  flag  =  saveUrlAs(photoUrl, filePath  +  fileName);
  out.println(
" Run ok!\n<BR>Get URL file  "   +  flag);
%>


]]>
完整的获取当前jsp文g路径的语?/title><link>http://www.aygfsteel.com/qclass/articles/39211.html</link><dc:creator>QpdcR方法、变量…?/dc:creator><author>QpdcR方法、变量…?/author><pubDate>Tue, 04 Apr 2006 09:09:00 GMT</pubDate><guid>http://www.aygfsteel.com/qclass/articles/39211.html</guid><wfw:comment>http://www.aygfsteel.com/qclass/comments/39211.html</wfw:comment><comments>http://www.aygfsteel.com/qclass/articles/39211.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/qclass/comments/commentRss/39211.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/qclass/services/trackbacks/39211.html</trackback:ping><description><![CDATA[ <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <img id="Codehighlighter1_0_8_Open_Image" onclick="this.style.display='none'; Codehighlighter1_0_8_Open_Text.style.display='none'; Codehighlighter1_0_8_Closed_Image.style.display='inline'; Codehighlighter1_0_8_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /> <img id="Codehighlighter1_0_8_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_0_8_Closed_Text.style.display='none'; Codehighlighter1_0_8_Open_Image.style.display='inline'; Codehighlighter1_0_8_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /> <span id="Codehighlighter1_0_8_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span> <span id="Codehighlighter1_0_8_Open_Text"> <span style="COLOR: #008000">/*</span> <span style="COLOR: #008000"> 错误Q?/span> <span style="COLOR: #008000">*/</span> </span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />String realPath </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> </span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">http://</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000"> </span> <span style="COLOR: #000000">+</span> <span style="COLOR: #000000"> request.getServerName() </span> <span style="COLOR: #000000">+</span> <span style="COLOR: #000000"> </span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">:</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000"> </span> <span style="COLOR: #000000">+</span> <span style="COLOR: #000000"> request.getServerPort() </span> <span style="COLOR: #000000">+</span> <span style="COLOR: #000000"> request.getContextPath();<br /><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />String realPath </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> </span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">http://</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000"> </span> <span style="COLOR: #000000">+</span> <span style="COLOR: #000000"> request.getServerName() </span> <span style="COLOR: #000000">+</span> <span style="COLOR: #000000"> </span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">:</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000"> </span> <span style="COLOR: #000000">+</span> <span style="COLOR: #000000"> request.getServerPort() </span> <span style="COLOR: #000000">+</span> <span style="COLOR: #000000"> request.getServletPath();<br /><img id="Codehighlighter1_238_246_Open_Image" onclick="this.style.display='none'; Codehighlighter1_238_246_Open_Text.style.display='none'; Codehighlighter1_238_246_Closed_Image.style.display='inline'; Codehighlighter1_238_246_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_238_246_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_238_246_Closed_Text.style.display='none'; Codehighlighter1_238_246_Open_Image.style.display='inline'; Codehighlighter1_238_246_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span> <span id="Codehighlighter1_238_246_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span> <span id="Codehighlighter1_238_246_Open_Text"> <span style="COLOR: #008000">/*</span> <span style="COLOR: #008000"> 正确Q?/span> <span style="COLOR: #008000">*/</span> </span> <span style="COLOR: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />String realPath </span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> </span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">http://</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000"> </span> <span style="COLOR: #000000">+</span> <span style="COLOR: #000000"> request.getServerName() </span> <span style="COLOR: #000000">+</span> <span style="COLOR: #000000"> </span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">:</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000"> </span> <span style="COLOR: #000000">+</span> <span style="COLOR: #000000"> request.getServerPort() </span> <span style="COLOR: #000000">+</span> <span style="COLOR: #000000"> request.getContextPath()</span> <span style="COLOR: #000000">+</span> <span style="COLOR: #000000">request.getServletPath().substring(</span> <span style="COLOR: #000000">0</span> <span style="COLOR: #000000">,request.getServletPath().lastIndexOf(</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">/</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">)</span> <span style="COLOR: #000000">+</span> <span style="COLOR: #000000">1</span> <span style="COLOR: #000000">); </span> </div> <img src ="http://www.aygfsteel.com/qclass/aggbug/39211.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/qclass/" target="_blank">QpdcR方法、变量…?/a> 2006-04-04 17:09 <a href="http://www.aygfsteel.com/qclass/articles/39211.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>javaq接Access数据库的代码http://www.aygfsteel.com/qclass/articles/39207.htmlQpdcR方法、变量…?/dc:creator>QpdcR方法、变量…?/author>Tue, 04 Apr 2006 09:07:00 GMThttp://www.aygfsteel.com/qclass/articles/39207.htmlhttp://www.aygfsteel.com/qclass/comments/39207.htmlhttp://www.aygfsteel.com/qclass/articles/39207.html#Feedback0http://www.aygfsteel.com/qclass/comments/commentRss/39207.htmlhttp://www.aygfsteel.com/qclass/services/trackbacks/39207.html import  java.sql. * ;
public   class  dbaccess {
 
public   static   void  main(String args[])  throws  Exception {
  Class.forName(
" sun.jdbc.odbc.JdbcOdbcDriver " );
  String dburl 
= " jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=Mobile.mdb " ; // 此ؓNO-DSN方式
  
// String dburl ="jdbc:odbc:odbcName"; // 此ؓODBCq接方式
  Connection conn = DriverManager.getConnection(dburl);
  Statement stmt
= conn.createStatement();
  ResultSet rs
= stmt.executeQuery( " select Top 20 * from MobileSection " );
  System.out.println(
" h\t地区\tcd\t省䆾\t区号 " );
  
while (rs.next()) {
   System.out.println(rs.getString(
1 ) + " \t " + rs.getString( 2 ) + " \t " + rs.getString( 3 ) + " \t " + rs.getString( 4 ) + " \t " + rs.getString( 5 ));
  }

  rs.close();
  stmt.close();
  conn.close();
 }

}

q行l果Q?/div>
---------- Run Java ----------
h 地区 cd 省䆾 区号
1300566 茂名 q东联?30卡 广东?668
1300567 茂名 q东联?07卡 广东?668
1300568 茂名 q东联?07卡 广东?668
1300569 珠v q东联?30卡 广东?756
1300570 惠州 q东联?30卡 广东?752
1300571 惠州 q东联?30卡 广东?752
1300572 惠州 q东联?30卡 广东?752
1300573 惠州 q东联?30卡 广东?752
1300574 惠州 q东联?30卡 广东?752
1300575 惠州 q东联?30卡 广东?752
1300576 珠v q东联?30卡 广东?756
1300577 珠v q东联?30卡 广东?756
1300578 珠v q东联?30卡 广东?756
1300579 珠v q东联?30卡 广东?756



]]>Java调用windowsE序http://www.aygfsteel.com/qclass/articles/39204.htmlQpdcR方法、变量…?/dc:creator>QpdcR方法、变量…?/author>Tue, 04 Apr 2006 09:06:00 GMThttp://www.aygfsteel.com/qclass/articles/39204.htmlhttp://www.aygfsteel.com/qclass/comments/39204.htmlhttp://www.aygfsteel.com/qclass/articles/39204.html#Feedback0http://www.aygfsteel.com/qclass/comments/commentRss/39204.htmlhttp://www.aygfsteel.com/qclass/services/trackbacks/39204.html׃工作中要使用Java调用4U Wma Mp3 Converter命o行将vox格式转换成WMA格式Q以方便在网中试听Q所以想到用java.lang.Runtime来处理这个问题。在使用q程中碰C一些以前没有留意的问题Q整理如下:

一 最单的调用方式
String cmd="WMAMP3Converter.exe";
java.lang.Runtime.getRuntime().exec(cmd+" \""+filePath+"\" /wma");
ȝQ此ҎQ要求可执行文g在Tomcat的工作目录中。一般的Q程序安装目录都在Tomcat目录之外Q所以用绝对\径来替代以上Ҏ?/p>

?使用全\径调用可执行文g
String cmd="C:\\WMA\\WMAMP3Converter.exe";
java.lang.Runtime.getRuntime().exec(cmd+" \""+filePath+"\" /wma");
ȝQ此调用方式执行没有问题Q后来测试完成后部v到服务器上,发现问题又出来了Q程序执行错误。分析原因,因ؓ本地试和服务器安装路径不同Q服务器安装软g的目录ؓC:\Program Files\4U Computing\WMA MP3 Converter\Q这里\径里有空|造成I格处断开Q所以命令行无法正确截取参数?/p>

?安全的全路径方式调用执行文g
String cmd="\"C:\\Program Files\\4U Computing\\WMA MP3 Converter\\WMAMP3Converter.exe\"";
java.lang.Runtime.getRuntime().exec(cmd+" \""+filePath+"\" /wma");
ȝQ在cmd串中Q把可执行文件的全\径用双引号包含,可以解册\径、文件名中包含空根{全角字W等问题?/p>

E序q行一D|间以后,发现有时候程序执行完后{换文件没有,E序没有错误Q而且服务器上有很多进E没有结束。原来调用可执行文gp|了,但是E序不知道,以ؓ成功了,然后l箋L转换后的文g来播攑֯致失败。分析原因,是因Z面的方式异步的,也就是说java提交q行文g的命令以后,立即转到播放模块?br />解决办法是让命令行同步方式执行Q也是ȝ序等待调用可执行文gl束以后再执行。(注:当然Q播放之前检查文件是否存在也是可以的Q这里是说明同步异步的问题。)

?异步方式调用外部可执行文?br />Process process=null;
String cmd="\"C:\\Program Files\\4U Computing\\WMA MP3 Converter\\WMAMP3Converter.exe\"";
process = java.lang.Runtime.getRuntime().exec(cmd+" \""+filePath+"\" /wma");
process.waitFor();
ȝQ构造一个Process对象Q将q行q程获取q来Q控制这个进E等待调用结束再l箋q行。OK?/p>

?Z说一下,使用Process对象以后Q可以用如下Ҏq回错误信息和输Z息,来进一步控制进E运行?br />process.exitValue()
process.getErrorStream()
process.getInputStream()
process.getOutputStream()



]]>
Java~略囄http://www.aygfsteel.com/qclass/articles/39206.htmlQpdcR方法、变量…?/dc:creator>QpdcR方法、变量…?/author>Tue, 04 Apr 2006 09:06:00 GMThttp://www.aygfsteel.com/qclass/articles/39206.htmlhttp://www.aygfsteel.com/qclass/comments/39206.htmlhttp://www.aygfsteel.com/qclass/articles/39206.html#Feedback0http://www.aygfsteel.com/qclass/comments/commentRss/39206.htmlhttp://www.aygfsteel.com/qclass/services/trackbacks/39206.html阅读全文

]]>
վ֩ģ壺 ǭ| | | ׯ| | | | | կ| Ĭ| | ƽ| ɽ| | ͨ| | Թ| ֱ| | մ| | Ԫ| ľ| | | ̨| | | Դ| | | | | ͬ| µ| Ȫ| ɽ| | ˮ| | ɽ|