<%@ page language="java" import="java.sql.*"%> <%@ page import="java.io.*"%> <% String DueID = request.getParameter("Rid").trim(); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String url="jdbc:odbc:SinoMessageBoard"; Connection con=DriverManager.getConnection(url,"sa","sa"); PreparedStatement sql=con.prepareStatement("select images from Images WHERE id ='"+DueID+"'"); ResultSet rs = sql.executeQuery(); rs.next(); InputStream in = rs.getBinaryStream("images"); response.reset(); response.setContentType("image/jpeg"); byte[] b = new byte[1024]; int len; while((len=in.read(b)) >0) response.getOutputStream().write(b,0,len); in.close(); rs.close(); %>文件2:<%@ page contentType="text/html;charset=gb2312"%><table> <tr> <td><img src="<%
out.println("<p align='center'><img border=\"0\" src=\"print_pic.jsp?picid="+ipicid+"&classid="+iclassid+"&ts=AAAAA\" width=100 height=100></p>");
%>" width=100 height=100 ></td> </tr> <tr> <td>这里的汉字无法显示</td> </tr></table>
out.println("<p align='center'><img border=\"0\" src=\"print_pic.jsp?picid="+ipicid+"&classid="+iclassid+"&ts=AAAAA\" width=100 height=100></p>");
%>" width=100 height=100 ></td> </tr> <tr> <td>这里的汉字无法显示</td> </tr></table>
解决方案 »
- 给个SSH(struts1.2,spring2.0,hibernate3.0)和MySQL的增删改查的小例子
- 求一个正则表达式
- tomcat
- (刚毕业的菜鸟问题)我想用搞java,请问要哪些软件,环境先不谈,如Eclipse。。。。。
- 高手帮我看看吧~~
- eclipse超简单问题。
- JSP怎么调用Web Services?
- 怎么运行半天又说找不到服务器?
- jsp中如何用结果集得到sqlserver6.5的smallint类型的字段值,在线等待!
- 急,请问高手在JSP用JDBC查询SQL后,乍样把查到的日期转为星期?
- jspsmartUpload的设置问题 !!!!急
- tomcat4.18连接池问题,抛出:DBcp could not obtain an idle db connection ,pool exhausted。
import="javax.sql.*"
import="javax.naming.*"
import = "java.sql.*"
import = "java.io.*"
%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<%
String add=null,medianame=null,exname=null,name1=null,sql=null,address=null,TypeMIME=null,SubTypeMIME=null,FilePathName=null,msg1=null;
String wwmj=null,wwmj1=null,EXT1=null;
int size1=0;
Connection Conn=null;
ResultSet Rs=null;
Statement Stmt = null;
add=request.getParameter("add");
if (add==null)
{
add="0";
}
if (add.equals("1"))
{
mySmartUpload.initialize(pageContext);
mySmartUpload.setTotalMaxFileSize(6000000);
//mySmartUpload.setAllowedFilesList("txt,doc,xls,jpg,gif"); mySmartUpload.upload();
for (int i=0;i<mySmartUpload.getFiles().getCount();i++)
{
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
if (!myFile.isMissing())
{
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("OracleDS");
Conn = ds.getConnection();
medianame=myFile.getFileName();
exname=myFile.getFileExt();
size1=myFile.getSize();
TypeMIME=myFile.getTypeMIME();
SubTypeMIME=myFile.getSubTypeMIME();
FilePathName=myFile.getFilePathName();
Statement aStmt = Conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
Rs = aStmt.executeQuery("SELECT MC,NR,DX,MIME,EXT FROM TEST");
Rs.moveToInsertRow();
Rs.updateString("MC",medianame);
Rs.updateInt("DX",size1);
Rs.updateString("MIME",TypeMIME);
Rs.updateString("EXT",exname);
byte buf[] = new byte[myFile.getSize()];
for (int j=0;j<myFile.getSize();j++)
{
//out.println(myFile.getBinaryData(j));
buf[j]=myFile.getBinaryData(j);
}
//File file1 = new File(FilePathName);
//FileInputStream fis = new FileInputStream(file1);
//InputStream is = fis;
//Rs.updateBinaryStream("NR",is,new Long(file1.length()).intValue()); myFile.fileToField(Rs,"NR");
//ByteArrayInputStream bas = new ByteArrayInputStream(buf);
//Rs.updateBytes("NR",buf);
Rs.insertRow();
Rs.moveToCurrentRow();
Rs.close();
Conn.close();
out.println("FieldName = " + medianame + "<BR>");
out.println("Size = " + myFile.getSize() + "<BR>");
out.println("FileExt = " + myFile.getFileExt() + "<BR>");
out.println("FilePathName = " + myFile.getFilePathName() + "<BR>");
out.println("ContentType = " + myFile.getContentType() + "<BR>");
out.println("ContentDisp = " + myFile.getContentDisp() + "<BR>");
out.println("TypeMIME = " + myFile.getTypeMIME() + "<BR>");
out.println("SubTypeMIME = " + myFile.getSubTypeMIME() + "<BR>");
break;
}
}
}
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="../css/text.css" type="text/css">
</head><body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="save.jsp?add=1" enctype="multipart/form-data">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td width="6%"><a href="aaaa.doc">asdasd</a> </td>
<td width="94%">
<input type="file" style="width:50%" name="file">
<input type="submit" name="Submit" value="上传">
</td>
</tr>
<tr>
<td width="6%"> </td>
<td width="94%"> </td>
</tr>
<tr>
<td width="6%"> </td>
<td width="94%">文件大小应小于<font color="#FF0000">6</font>兆 </td>
</tr>
</table>
</form>
</body>
</html>
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
public class getImage extends HttpServlet
{
private String CONTENT_TYPE = "image/gif";
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
int ID = 0;
ServletOutputStream outt = response.getOutputStream();
try
{
ID = Integer.parseInt(request.getParameter("id"));
//System.out.println(ID);
}catch (Exception e){
response.sendRedirect("../ErroePage.jsp");
return;
}
try
{
byte[] buff = this.getCover(ID);
response.setContentType(CONTENT_TYPE);
outt.flush();
outt.write(buff);
outt.flush();
}catch (IOException ioe){
ioe.printStackTrace();
}
}
private synchronized byte[] getCover(int ID1)
{
Context ctx=null;
Connection Conn = null;
Statement stmt = null;
ResultSet rs = null;
byte[] buf = null;
try{
ctx = new InitialContext();
//DataSource ds = (DataSource)ctx.lookup("OracleDS");
DataSource ds = (DataSource)ctx.lookup("SqlServerDs");
Conn = ds.getConnection();
String searchSql="SELECT MIME,NR FROM TEST WHERE ID="+ ID1;
stmt = Conn.createStatement();
rs = stmt.executeQuery(searchSql);
rs.next() ;
CONTENT_TYPE = rs.getString("MIME");
buf = rs.getBytes("NR");
//System.out.println(CONTENT_TYPE);
}catch(Exception sqle){
System.err.println("Error in CoverServlet : getCover()-" + sqle);
sqle.printStackTrace() ;
}finally{
try
{
stmt.close() ;
Conn.close() ;
}catch (Exception e){
e.printStackTrace();
}
}
return buf;
}
public void destroy()
{
}
} <p><a href="aaaa.doc">adfasdfasdf </a><img src="../servlet/getImage?id=1" width="103" height="34">
<a href="../servlet/getImage?id=2">SFADFASD</a> </p>
<p> </p>