jsp上传图片问题 在线等!!
表单页面
<HTML>
<HEAD>
<TITLE> Image File </TITLE>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
</HEAD>
<BODY>
<FORM METHOD=POST ACTION= "testimage.jsp ">
<INPUT TYPE= "text " NAME= "content "> <BR>
<INPUT TYPE= "file " NAME= "image "> <BR>
<INPUT TYPE= "submit "> </FORM>
</BODY>
</HTML>
动作页面:
<%@ page contentType= "text/html;charset=gb2312 "%>
<%@ page import= "java.sql.* " %>
<%@ page import= "java.util.* "%>
<%@ page import= "java.text.* "%>
<%@ page import= "java.io.* "%>
<%
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ").newInstance();
String url= "jdbc:odbc:test ";
String user= "sa ";
String password= "123456 ";
Connection conn=DriverManager.getConnection(url,user,password);
String content=request.getParameter( "content ");
String filename=request.getParameter( "image ");
FileInputStream str=new FileInputStream(filename);
String sql= "insert into test(id,content,image) values(1,?,?) ";
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setString(2,content);
pstmt.setBinaryStream(3,str,str.available());
pstmt.execute();
out.println( "Success,You Have Insert an Image Successfully ");
%>
系统提示错误:
An error occurred at line: 6 in the jsp file: /testimage.jsp
Syntax error on token "Invalid Character ", delete this token
3: <%@ page import= "java.util.* "%>
4: <%@ page import= "java.text.* "%>
5: <%@ page import= "java.io.* "%>
6: <%
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ").newInstance();
7: String url= "jdbc:odbc:test ";
8: String user= "sa ";
9: String password= "123456 ";
我的数据库为SQL Server2000 test表的为id,content,image(为image类型)
我的数据库是 SQL SERVER2000 该怎么弄呢 系统提示错误的那行是我从我其他程序上复制来的 怎么那行在其他地方没事呢 应该不是那行的错误吧 是它关联的地方错了吧 希望有高人指点
------解决方案--------------------1、文件上传
FORM
要加入enctype= "multipart/form-data "
ACTION或SERVLET
import org.apache.commons.fileupload.DiskFileUpload;
import org.apache.commons.fileupload.FileItem;
基本方法如下:
String temp=request.getSession().getServletContext().getRealPath( "/ ")+ "temp "; //临时目录