Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet Full path of image to save it in a folder

Have Programming Question? Ask it here!
 
 
 


Sourabh Chourasia
Full path of image to save it in a folder
1 Answer(s)      2 years and 4 months ago
Posted in : JSP-Servlet


Sir ,I am trying to upload a file but only sends file name as parameter. I want a code that would help me to find that image path &upload it as well. I am just a beginner in jsp &trying to create a project.


Advertisement
View Answers

April 3, 2012 at 10:18 PM


Hi,

If you wish to upload files in the local context of your project, then you may first create a folder under WEB_INF. call it anything you want. Then considering the fact that you are a beginner, I would suggest that you create a servlet and call it from the page using method POST. Within the servlet, there would be two options for you to explore:- 1. saving the file uploaded into the database, which would require the use of either JDBC or JPA, whichever is known to you. 2. saving the file in a folder.

code is given below:-

package pack;

import java.io.*;
import java.sql.DriverManager;
import java.util.Scanner;

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import javax.servlet.annotation.MultipartConfig;

import java.sql.*;

/**
 * Servlet implementation class uploadServlet
 */
@WebServlet("/upload.do")
@MultipartConfig
public class uploadServlet extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        Part p1=request.getPart("title");
        Part p2=request.getPart("filesel");
        InputStream is=p2.getInputStream();
        Scanner sc=new Scanner(p1.getInputStream());
        String title=sc.next();
        sc=new Scanner(p2.getContentType());
        String type=sc.next();
        try
        {
            String path=request.getServletContext().getRealPath("folder url where u want to store your uploaded file");
            FileOutputStream fos=new FileOutputStream(path);
            byte buf[]=new byte[is.available()];
            is.read(buf);
            fos.write(buf);
            fos.flush();
            fos.close();
            // use this part only if you wish to store files in database
            Class.forName("sun.jdbc.odbc.Driver");
            Connection con=DriverManager.getConnection("jdbc:odbc:databasename");
            PreparedStatement ps=con.prepareStatement("insert in table (picName,picPath) values(?,?) ");
            ps.setString(1, title);
            ps.setString(2, path);
            ps.execute();
            ps.close();
            con.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        }
    }

Note that the part where I set the path for storage has to be either one of local context as mentioned before or it can be a folder created anywhere in your machine.

Hope this solves your query.

Regards, Abhineet Verma



Related Tutorials/Questions & Answers:
Full path of image to save it in a folder
Full path of image to save it in a folder  Sir ,I am trying to upload... to find that image path &upload it as well. I am just a beginner in jsp... in the local context of your project, then you may first create a folder under WEB
image save to folder in java
image save to folder in java  Hi, I am working with java. In my application i want to give facility to user to add and change image. I use open... folder and that path stored into database, for furhter retrivation. Please guide me
Advertisements
Java- Save Image into project folder in web application
Java- Save Image into project folder in web application  I have a requirement of saving the image into project folder .. which is a web application... want to save the image..when I am trying to create empty folder and get
write file in aplication folder with out giving full path - WebSevices
write file in aplication folder with out giving full path  i have a simple java class by the help of this java class i want to write file in application folder with out giving full path like c:/data/aa
Image name,image path into database and image into folder using jsp
Image name,image path into database and image into folder using jsp  How to insert image path and image name into oracle database and image into folder using jsp
i want to save image on server folder. and i want to save URL of this folder and name of image in database
i want to save image on server folder. and i want to save URL of this folder and name of image in database  hi i want to save image on server folder. and i want to save URL of this folder and name of image in database.on click
How to store user name,city,state,image path into database and image into folder using jsp
How to store user name,city,state,image path into database and image into folder using jsp  How to store user name,city,state,image path into database and image into folder using jsp
how to store image in folder and stored image path in mysql database using JSP
how to store image in folder and stored image path in mysql database using JSP  how to store image in folder and stored image path in mysql database using JSP
session_save_path()
session_save_path() session_save_path() command returns the current working directory path.  Syntax session_save_path(); Example: <?php echo session_save_path(); #return the current working directory path ?>  
How to get the full path location using <input type=file>
How to get the full path location using input type=file  Hi. I have used input type=file> in HTML to select an image. But it selects only the image but not with its full path location. how to do it? Thanks in advance
How to upload and save a file in a folder - Java Beginners
How to upload and save a file in a folder  Hi How to upload and save a file in a folder? for example Agreement.jsp File: So when... in solving the problem : Image Upload
how to upload multiple files in jsp and saving the path in database and the file in folder
, for example, i need to save a image for the photo of candidate and resume...how to upload multiple files in jsp and saving the path in database and the file in folder  how to upload multiple files in jsp and saving the path
Jmagick write image to a specific folder
to save the resized image to a specific location try{ String path... and save the resized images to the another location. for example : get an image to resize from c:\myDirectory\images and save the resized image to c:\myDirectory
inserting an path of an image in database - JDBC
time its full path should be inserted in the database(MS Sql 2000).. I m able to save it in folder..but can you plz tell me how an the full path of image can...inserting an path of an image in database  hello kindly help related
image upload in webapp/upload folder
image upload in webapp/upload folder  sir i want to store upload image in my project directory WebApp/Upload_image/ pls send the jsp servlet code when i upload the image one error found "system cannot found the specified path
to obtain image path
"); // create a file object for image by specifying full path of image...to obtain image path   i have made a web application in which you can... or BROWSE button . and i am expecting to obtain the complete path of the image from
save the uploading image with user specified name
save the uploading image with user specified name  My form consists of a textbox and an upload image with submit button.When i submit the form I want to save the uploaded image in a folder with user specfied name
save the uploading image with user specified name
save the uploading image with user specified name  My form consists of a textbox and an upload image with submit button.When i submit the form I want to save the uploaded image in a folder with user specfied name
How to save image on the server by applet
How to save image on the server by applet  HI, in my project I am... If user want to export this chart as GIF format then this chart should be save as a gif image on the server directory. Can any Body help me how can I do it Thanks
How to save image on the server by applet
How to save image on the server by applet  HI, in my project I am... If user want to export this chart as GIF format then this chart should be save as a gif image on the server directory. Can any Body help me how can I do it Thanks
how to insert the physical path of an image in database - JDBC
how to insert the physical path of an image in database  hello I m... the image is captured it is saved in folder in a project folder and at the same time... path.. and also how to retrive that image path and show that picture in a small
Delete image from folder - JSP-Servlet
Delete image from folder  Hi Thanks Rajnikant to given me reply i am not storing my image in db just userid comming from db means my image name like : Pie(userid).png which alocated in my server folder when
How to make an image full text.
How to make an image full text.     ... an image full text because this tutorial has made it easy. It will provide another option to make an image full text so follow now. Open a file: First open
how to display or retrive an image in jsp whose path is stored in oracle database
how to display or retrive an image in jsp whose path is stored in oracle database  how to display or retrive an image in jsp whose path is stored in oracle database and the image is stored in my pictures folder
How to create file and save it into user defined path using jsp/servlet?
How to create file and save it into user defined path using jsp/servlet?  Hi.. Onclick event I have created one file.When file will create it should asked where to save file(like browse option
Delete image from folder - JSP-Servlet
. that image name based on user id and that image is going to on folder in server after...Delete image from folder  Dear All, i used some coding... creating a new png image. in my project if two user will be login same time meanse
How to copy an jpeg image from one folder to other folder using jsp
How to copy an jpeg image from one folder to other folder using jsp  How to copy an image from one folder to another folder using jsp
Save profile and image to mysql database, and view the image in another jsp page
Save profile and image to mysql database, and view the image in another jsp page  Pls. need help in saving the profile info with the image in mysql database.. some basic code pls in jsp... thanks in advance
How to get full path of the uploaded file using commons fileupload jar file
How to get full path of the uploaded file using commons fileupload jar file  I want to upload file to database with its full path. Because... type.I am in need to get the full path. Can anyone help me to get the full path
Insert image from user using and save in database
Insert image from user using and save in database  when i am trying to upload a image from user and trying to save into oracle9i database...) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) note The full
How to save image after edit in php
How to save image after edit in php  Hello, I have create a simple image editor with the effected of brightness, contrast, and desaturat etc. I have... successfully but i don't know how to replace orignal image with the effects. please
how to save uploaded image in database using javascript
how to save uploaded image in database using javascript  Please can you tell me how to store uploaded image in database using java I'll use the upload code as extArray = new Array(".gif", ".jpg", ".png"); function LimitAttach
How to copy an jpeg image from one folder to other folder using jsp
How to copy an jpeg image from one folder to other folder using jsp  ... be in my image folder...so,How to copy an jpeg image from one folder to other folder using jsp or servlet
How can store image in server folder when deployed with a .war file?
How can store image in server folder when deployed with a .war file?  Hi all; When I am using application.getRealPath() , it return null when deployed with a .war file and when I use hard code it shows syntax error or path
Image is in same folder where the java file is located - Swing AWT
Image is in same folder where the java file is located  dear sir It is there in the same folder..means the photograph.jpg file is created in the same folder where my java file is present... wat I should do sir
How to store multiple images in folder and images path in database at a time using jsp?
How to store multiple images in folder and images path in database at a time using jsp?  I wanna browse multiple images in one form and store them in one folder and their path into datrabase
i am inserting an image into database but it is showing relative path not absolute path
i am inserting an image into database but it is showing relative path not absolute path   hi my first page......... Image Enter your name: Upload photo: Father name: Age: Username: Password Qualification: Gender: Phone
i am inserting an image into database but it is showing relative path not absolute path
i am inserting an image into database but it is showing relative path not absolute path   hi my first page......... Image Enter your name: Upload photo: Father name: Age: Username: Password Qualification: Gender: Phone
how to store image upload path to mssql database
how to store image upload path to mssql database  hi there!!, i need help in storing the image upload path into the database. basically i just use file select to upload the image from jsp to database. however when i click submit
how to store image upload path to mssql database
how to store image upload path to mssql database  hi there!!, i need help in storing the image upload path into the database. basically i just use file select to upload the image from jsp to database. however when i click submit
how to store image upload path to mssql database
how to store image upload path to mssql database  hi there!!, i need help in storing the image upload path into the database. basically i just use file select to upload the image from jsp to database. however when i click submit
how to store image upload path to mssql database
how to store image upload path to mssql database  hi there!!, i need help in storing the image upload path into the database. basically i just use file select to upload the image from jsp to database. however when i click submit
i am inserting an image into database but it is showing relative path not absolute path
i am inserting an image into database but it is showing relative path not absolute path   hi my first page......... <html> <head> <title>Image</title> </head> <body bgcolor="lavender">
pls provide common path to set image in flex - XML
pls provide common path to set image in flex  hi, pls provide common setpath to image in flex.when i give ful path like these C:\eclipse\workspace... the coding in mxml to set common path of image in flex
How to access the image file from project folder itself while writing to pdf using itext?
How to access the image file from project folder itself while writing to pdf using itext?  I am writing a pdf using itext where i add a image... to search for the image in the domain folder of the glassfish location.But i want
Upload Image and save in database using jsp-servlet mvc
Upload Image and save in database using jsp-servlet mvc  Here is my...;/TD> <td><input type="file" name="Image" size="20" value="">...="file" name="Image" size="20" value=""></TD> </tr> <tr>
Upload Image and save in database using jsp-servlet mvc
Upload Image and save in database using jsp-servlet mvc  Here is my...;/TD> <td><input type="file" name="Image" size="20" value=""><..." name="Image" size="20" value=""></TD> </tr> <tr> <
how to get the image path when inserting the image into pdf file in jsp - JSP-Servlet
how to get the image path when inserting the image into pdf file in jsp  Hi Friend, my image path;C:/images/photo.jpg. i am getting the below error error: The type Image is ambiguous document.open(); Image
how to get the image path when inserting the image into pdf file in jsp - JSP-Servlet
how to get the image path when inserting the image into pdf file in jsp ... that your system does not find the image, you have specified.Set the path of an image...")); document.open(); Image image = Image.getInstance("C:/image2.png"); Image
full coding
full coding  class IdentifyMyParts { public static int x=7; public int y=3;} IdentifyMyParts a = new IdentifyMyParts(); IdentifyMyParts b = new IdentifyMyParts(); a.y = 5; b.y = 6; a.x = 1; b.x = 2; System.out.println("a.y
Advertisements
 

 

 

DMCA.com