• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

uploading.....

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Please give me , how I write code for uploading files in java. I am using java, sevlet,html for developing source code.
thanks a lot.
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a very repeated question in this forum. Search the forums before posting is a good practice.Here you have some related threads:
https://coderanch.com/t/355011/Servlets/java/Sample-servlet-handling-file-upload
https://coderanch.com/t/347821/Servlets/java/file-upload-servlet
[ September 12, 2002: Message edited by: Juanjo Bazan ]
 
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use jsmsmartupload class. www.jspsmart.com. And yes, it's free.
 
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is the code for inserting imahe files suing java servlets
import java.lang.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.io.*;
//public class WriteBlob
public class WriteBlob extends HttpServlet
{
// private static Connection con = null;
private static PreparedStatement ps;
//public static void main(String[] argv)
public void service(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
PrintWriter out=res.getWriter();
res.setContentType("text/html");
try
{
String name=req.getParameter("text1");
String type=req.getParameter("text2");
String file1=req.getParameter("file");
Connection con = null;

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
con=DriverManager.getConnection("jdbc racle:thin:@oracle:1521 RCL","scott","tiger");
/*Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc dbc:img","sa","");*/
//File file =new File("fevicon.ico");
File file =new File(file1);
InputStream is = new FileInputStream(file);
ps =con.prepareStatement("insert into emp_photo VALUES(?,?,?)");
ps.setString(1,name);
ps.setString(2,type);
out.println("name is" +name+"<br>");
out.println("type is" +type);
out.println("pic is" +file1);
out.println("Inserted Succesfully***************..");
ps.setBinaryStream(3,is,Integer.MAX_VALUE);
out.println("Inserted Succesfully..");
ps.execute();
out.println("Inserted Succesfully..");
con.close();
out.println("<a href=http://subra:7001/GetBlob><b>Image</b></a>");
out.println("<br>");
out.println("<a href=http://subra:7001/img.jsp><i>Home</i></a>");
//res.sendRedirect("http://subra:7001/img.jsp");

}
catch (Exception ex)
{
ex.printStackTrace(out);
}
}
}
This is the code for retreving images from database

import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class GetBlob extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
try
{
res.setContentType("text/plain");
PrintWriter out = res.getWriter();
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection con =DriverManager.getConnection("jdbc racle:thin:@oracle:1521 RCL","scott","tiger");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT picture from emp_photo where empno = 'red' and photo_format='jpg' ");
if(rs.next())
{
InputStream is = rs.getBinaryStream(1);
InputStreamReader isr=new InputStreamReader(is);
BufferedReader bfr = new BufferedReader(isr);
String str=null;

while((str=bfr.readLine())!=null)
{
out.println(str);
}
}

rs.close();
stmt.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
 
Author
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi there
u can even use com.oreilly package by jason hunter from www.servlets.com
hth
malhar
 
If you look closely at this tiny ad, you will see five bicycles and a naked woman:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic