jsp读取数据库的图片
请教各位大侠,我已经把图片的路径存入数据库了,下面的代码要怎么样修改才能使图片显示在页面上,谢谢!<%@pagelanguage="java"import="java.s...
请教各位大侠,我已经把图片的路径存入数据库了,下面的代码要怎么样修改才能使图片显示在页面上,谢谢!
<%@ page language="java" import="java.sql.*" pageEncoding="gb2312"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<%@ page import="java.io.*"%>
<%!public String code(String str) {
String s = str;
try {
byte[] b = s.getBytes("ISO-8859-1");
s = new String(b);
return s;
} catch (Exception e) {
return s;
}
}%>
<html>
<body>
<%
String sqlString = null;
String username = code(request.getParameter("username"));
if (username == null || username.trim().length() == 0)
sqlString = new String("select * from usertable");
else
sqlString = new String(
"select * from usertable where username like'%"
+ username.trim() + "%'");
%>
<%
Connection con;
Statement sql;
ResultSet rs;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException e) {
out.print("类找不到!");
}
try {
con = DriverManager.getConnection(
"jdbc:sqlserver://localhost:1433;DatabaseName=users",
"sa", "11011");
sql = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs = sql.executeQuery(sqlString);
rs.last();
int row = rs.getRow();
out.print(" <table border>");
out.print(" <form action=index.jsp method=post>");
out.print(" <tr> <td>查询姓名 </td>");
out.print(" <td colspan=7>");
out.print(" <input type=text name=username>");
out.print(" <input type=submit value=提交>");
out.print(" </td> </tr> </form>");
out.print(" <tr> <td colspan=8 align=center>用户数据(共" + row
+ "条数据) </td> </tr>");
out.print(" <tr>");
out.print(" <td width=100>" + "用户id号");
out.print(" <td width=100>" + "用户姓名");
out.print(" <td width=100>" + "用户年龄");
out.print(" <td width=100>" + "用户性别");
out.print(" <td width=100>" + "图片");
out.print(" </tr>");
rs.beforeFirst(); //移到最后一行的后面
while (rs.next()) {
out.print(" <tr>");
out.print(" <td>" + rs.getInt(1) + " </td>");
out.print(" <td>" + rs.getString(2) + " </td>");
out.print(" <td>" + rs.getInt(3) + " </td>");
out.print(" <td>" + rs.getString(4) + " </td>");
out.print(" <td>" + rs.getBinaryStream(5) + " </td>"); /************************
out.print(" </tr>");
}
out.print(" </table>");
con.close();
} catch (SQLException ee) {
out.print(ee);
}
%>
</body>
</html> 展开
<%@ page language="java" import="java.sql.*" pageEncoding="gb2312"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<%@ page import="java.io.*"%>
<%!public String code(String str) {
String s = str;
try {
byte[] b = s.getBytes("ISO-8859-1");
s = new String(b);
return s;
} catch (Exception e) {
return s;
}
}%>
<html>
<body>
<%
String sqlString = null;
String username = code(request.getParameter("username"));
if (username == null || username.trim().length() == 0)
sqlString = new String("select * from usertable");
else
sqlString = new String(
"select * from usertable where username like'%"
+ username.trim() + "%'");
%>
<%
Connection con;
Statement sql;
ResultSet rs;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException e) {
out.print("类找不到!");
}
try {
con = DriverManager.getConnection(
"jdbc:sqlserver://localhost:1433;DatabaseName=users",
"sa", "11011");
sql = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs = sql.executeQuery(sqlString);
rs.last();
int row = rs.getRow();
out.print(" <table border>");
out.print(" <form action=index.jsp method=post>");
out.print(" <tr> <td>查询姓名 </td>");
out.print(" <td colspan=7>");
out.print(" <input type=text name=username>");
out.print(" <input type=submit value=提交>");
out.print(" </td> </tr> </form>");
out.print(" <tr> <td colspan=8 align=center>用户数据(共" + row
+ "条数据) </td> </tr>");
out.print(" <tr>");
out.print(" <td width=100>" + "用户id号");
out.print(" <td width=100>" + "用户姓名");
out.print(" <td width=100>" + "用户年龄");
out.print(" <td width=100>" + "用户性别");
out.print(" <td width=100>" + "图片");
out.print(" </tr>");
rs.beforeFirst(); //移到最后一行的后面
while (rs.next()) {
out.print(" <tr>");
out.print(" <td>" + rs.getInt(1) + " </td>");
out.print(" <td>" + rs.getString(2) + " </td>");
out.print(" <td>" + rs.getInt(3) + " </td>");
out.print(" <td>" + rs.getString(4) + " </td>");
out.print(" <td>" + rs.getBinaryStream(5) + " </td>"); /************************
out.print(" </tr>");
}
out.print(" </table>");
con.close();
} catch (SQLException ee) {
out.print(ee);
}
%>
</body>
</html> 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |