我需要使用 servlet 处理文件上传,如下所示:
package com.limrasoft.image.servlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.sql.*;
@WebServlet(name="serv1",value="/s1")
public class Account extends HttpServlet{
public void doPost(HttpServletRequest req,HttpServletResponse res)throws
ServletException,IOException{
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connecection con=null;
try{
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","sajid");
PrintWriter pw=res.getWriter();
res.setContentType("text/html");
String s1=req.getParameter("un");
string s2=req.getParameter("pwd");
String s3=req.getParameter("g");
String s4=req.getParameter("uf");
PreparedStatement ps=con.prepareStatement("insert into account(?,?,?,?)");
ps.setString(1,s1);
ps.setString(2,s2);
ps.setString(3,s3);
File file=new File("+s4+");
FileInputStream fis=new FileInputStream(fis);
int len=(int)file.length();
ps.setBinaryStream(4,fis,len);
int c=ps.executeUpdate();
if(c==0){pw.println("<h1>Registratin fail");}
else{pw.println("<h1>Registration fail");}
}
finally{if(con!=null)con.close();}
}
catch(ClassNotFoundException ce){pw.println("<h1>Registration Fail");}
catch(SQLException se){pw.println("<h1>Registration Fail");}
pw.flush();
pw.close();
}
}
但它会导致错误页面:
HTTP 状态 500 - Servlet3.java(系统找不到指定的文件)
这是如何引起的,我该如何解决?