wood burning stoves 2.0*
The moose likes Servlets and the fly likes image loading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "image loading" Watch "image loading" New topic
Author

image loading

sharad goswami
Ranch Hand

Joined: Jan 18, 2001
Posts: 51
Hi! i have a project which requires me to load image files of the client to my server.I am using html.now how do i do it?please help me or suggest a good book on this.


Stop The World I Want To Get Off.
v velus
Greenhorn

Joined: Sep 07, 2001
Posts: 14
/*
upload-FileUpload.java
NOTE: This file is a generated file.
Do not modify it by hand!
*/
package upload;

// custom imports for FileUpload
// add your custom import statements here
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import com.oreilly.servlet.MultipartRequest;
import java.util.*;

public class FileUpload extends javax.servlet.http.HttpServlet
{
protected boolean create() throws java.lang.Exception
{
return true;
}
public FileUpload()
{ // Constructor.
}
private void unhandledEvent( String listenerName, String methodName, java.lang.Object event )
{
}
/**
* destroy Method
*/
public void destroy()
{
super.destroy();
// TODO: implement
}
/**
* doGet Method
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType( "text/html" );
PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println("<HEAD><TITLE>FileUpload</TITLE></HEAD>");
out.println("<BODY>");
out.println("<H1>FileUpload</H1>");
out.println("Hello World!");
out.println("<P>Default Implementation From PowerJ</P>");
out.println("</BODY></HTML>");
// TODO: implement
}
/**
* doPost Method
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{

PrintWriter out = response.getWriter();
try{
response.setContentType("text/html");
out.println("<HTML>");
out.println("<head><Title>Decoded Uploaded File</title><head>");
out.println("<body>");
out.println("<H1>UploadFile</h1>");
// path must be absolute to upload dir
// This is the decoder class that extracts the parameters and transfer file
// request argument = Http input stream
// c:\\temp\\upload = directory to save file
// 15*1024*1024 = 15mb max size file
MultipartRequest multi = new MultipartRequest(request, "c:\\temp\\upload",15*1024*1024);

// Lists form parameters
out.println("Params:");
Enumeration params = multi.getParameterNames();
out.println("<pre>");
while (params.hasMoreElements()) {
String name = (String)params.nextElement();
String value = multi.getParameter(name);
out.println(name + " = " + value);
}
out.println("</pre>");

// Show details of uploaded file
out.println("Files:");
Enumeration files = multi.getFileNames();
out.println("<pre>");
while (files.hasMoreElements()) {
String name = (String)files.nextElement();
String filename = multi.getFilesystemName(name);
String type = multi.getContentType(name);
File f = multi.getFile(name);
out.println("name: " + name);
out.println("filename: " + filename);
out.println("type: " + type);
if (f != null) {
out.println("f.toString(): " + f.toString());
out.println("f.getName(): " + f.getName());
out.println("f.exists(): " + f.exists());
out.println("f.length(): " + f.length());
out.println();
}
out.println("</pre>");
}
}catch (Exception e){
out.println("<pre>");
e.printStackTrace(out);
out.println("</pre>");
}
out.println("</body></html>");
}
/**
* init Method
*/
public void init(ServletConfig config) throws ServletException
{
super.init(config);
// TODO: implement
}
/****************************************
* data members
****************************************/

// add your data members here
}
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Hey 'v', you could just provide a link to the other thread
Dave
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: image loading
 
Similar Threads
Handling the Event of the Image
Retrievin image that is stored as Blob in database.
Image
Quality image
urgency!!! In Japplet, how to make......