jsp image display

jsp image display

this is my saveImage.jsp file:

   <%
ServletContext context = pageContext.getServletContext();
String initPath = context.getInitParameter("file-upload");
String filePath=initPath;
String path=(request.getRequestURL().toString());
String urlPath=path.substring(0,path.lastIndexOf('/')+1)+"files/";
String userName=(String)session.getAttribute("username");
String password=(String)session.getAttribute("password");
String userId="";
String query="";
userName="jar";
password="gg";

// String connectionURL = "jdbc:mysql://localhost:3306/student";

try 
{
    Class.forName("com.mysql.jdbc.Driver").newInstance();
   Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/student","root","12345");  
   Statement st=con.createStatement();
    //System.out.println("session attribute"+userName+"password"+password);
    String ImageFile="";
    String itemName = "";
    boolean isMultipart = ServletFileUpload.isMultipartContent(request);
    if (!isMultipart) {
        out.println("File Not Uploaded");
    } 
    else
    {
        FileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload upload = new ServletFileUpload(factory);
        List items = null;
        try
        {
            items = upload.parseRequest(request);
        }
        catch (FileUploadException e)
        {
        e.getMessage(); 
        }
        Iterator itr = items.iterator();
        while (itr.hasNext())
        {
            FileItem item = (FileItem) itr.next();
            if (item.isFormField())
            {
                String name = item.getFieldName();
                String value = item.getString();
                if(name.equals("ImageFile"))
                {
                    ImageFile=value;
                }
            }
            else
            {
                try
                {

                    itemName = item.getName();
                    File checkDir = new File(filePath);
                    File savedFile=null;
                    if(checkDir.exists())
                    {   
                        itemName=itemName;
                        savedFile= new File(filePath+itemName);                             
                    }
                    else{
                        checkDir.mkdir();
                        savedFile= new File(filePath+itemName);                         
                    }
                    item.write(savedFile);
                    String updateQuery="update stu_info set image_path=? where username=? AND password=?";
                       PreparedStatement pstmt=con.prepareStatement(updateQuery);
                       pstmt.setString(1,itemName);
                       pstmt.setString(2,userName);
                       pstmt.setString(3,password);
                       int id = pstmt.executeUpdate();
                    out.print("success");
                }
                catch (Exception e)
                {
                    System.out.println("error message is"+e.getMessage());
                     out.print("Error"+e.getMessage()); 
                    out.print("error");
                }
            }
        }           
    }
}
catch (Exception e){        
    System.out.println("error message is"+e.getMessage());
    out.print("error");
}

%> how can i create session fo userName and password so that i dont have to write particular userName and password on line 10 and 11

View Answers









Related Tutorials/Questions & Answers:
display image on jsp
is downloading on jsp. show i can open it. but i want to display that image on jsp...display image on jsp  how to display image from database which path is coming in string. i want to display image and its discription and price
image display - JSP-Servlet
image display  how to display image that store in mysql database... column have BLOB datatype....  Hi Friend, Please visit the following link: http://www.roseindia.net/jsp/retrieve-image.shtml Thanks
Advertisements
display image using jsp
display image using jsp  display image using jsp and phonegap on emulator of eclipse   Here is a simple jsp code that displays an image on browser. <%@ page import="java.io.*" %> <%@page contentType="image/gif
Jsp Image Display
Jsp Image Display  Hi,i need to display image in a Box like in profile photo,when i click on the browse button,file gets open and the selected image... to save it in a database....Kindly post JSP codes..Its Urgent, I m very thankful t
image display in jsp - Java Beginners
image display in jsp  i uploaded the image and how can i print that image in next jsp page....  Hi friend, read for more information, http://www.roseindia.net/jsp/file_upload/employee_upload_profile_image.shtml
jsp image display
jsp image display  this is my saveImage.jsp file: <% ServletContext context = pageContext.getServletContext(); String initPath...); String updateQuery="update stu_info set image_path=? where
JSP:select image for db and display in image tag
JSP:select image for db and display in image tag  Hi, i am new to this forum. My query is that, i am trying to display image in image tag but i am...(); response.setContentType("image/jpg"); response.getOutputStream().write(rb,0,len
JSP:select image for db and display in image tag
JSP:select image for db and display in image tag  Hi, i am new to this forum. My query is that, i am trying to display image in tag but i am...); response.getOutputStream().flush(); } i think, this code will display image
JSP:select image for db and display in image tag
JSP:select image for db and display in image tag  Hi, i am new to this forum. My query is that, i am trying to display image in tag but i am...); response.getOutputStream().flush(); } i think, this code will display image
how to display one image on jsp through java
how to display one image on jsp through java  Hi, I wanted to display one image on my jsp file like social networking sites. But the scenario...://upload/image.jpg . what is the procedure to get that and display on my jsp page
Retrview image from sqlserver2000 and display in jsp - JSP-Servlet
Retrview image from sqlserver2000 and display in jsp  How to retreview image from sqlserver2000 to jsp? pls give the solution i am using Tomcat 4... for more information, http://www.roseindia.net/jsp/ Thanks
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 display image in jsp from database using Servlet?
How to display image in jsp from database using Servlet?  Hi, How to display image in jsp from database using Servlet? Thanks   Hi, You will find code and example program at Retrieve image from database using Servlet
how to display image and text in single jsp page from the mysql database
how to display image and text in single jsp page from the mysql database  hello please help me to display the image and text in single jsp page from mysql database if have any reference code please send me Thanks in advance
Upload and display image and text records using JSP and Oracle
Upload and display image and text records using JSP and Oracle  Hi all, I'm using JSP and Oracle 10g. I could retrieve and display records from database. But i couldnot retrieve and display image. I want to store
Retrieve image from database using servlet and display in JSP
Retrieve image from database using servlet and display in JSP  Hi, I... to use MySQL Database from JSP page. How to retrieve image from database using servlet and display in JSP? Thanks
image display
for uploading image in ms access database and also seen the result of displaying image from access database but Sir I want that how I display image from database...image display  hello sir this is saurav srivastav, I am developing my
pre Page load display an image loading - JSP-Servlet
pre Page load display an image loading  hi, We have requirement... to display a loading image. How to achieve this requirement. Thanks Manu  Hi Friend, Do you want to display image before loading page? Please clarify
Display image
Display image  How to Pass image from html to jsp and display that image using jsp   Here is an example that pass an image path from the html page to jsp page and display it. 1)page.html: <%@ page language="java
image display
to display in image from databse plz help me i will wait for ur reply...image display  sir the answer which you have sent to me is already I have I want to know that the syntax which you have writen for display
image display
to display in "div image from databse /div" plz help me i will wait for ur reply...image display  sir the answer which you have sent to me is already I have I want to know that the syntax which you have writen for display
How display a Image on servlet from file upload - JSP-Servlet
How display a Image on servlet from file upload  Dear Sir, I were ask a question that How display the Image on servlet through file upload. Today I get your answer. But Sir, It code not display the image on servlet
How display a image on servlet from file upload - JSP-Servlet
How display a image on servlet from file upload  Dear Sir, My issue is: How display a image on servlet from file upload I receive your answer today. That is: Answers Hi friend, I am sending running code. Image
How display a image on servlet from file upload - JSP-Servlet
How display a image on servlet from file upload   Dear Sir, My Question is: How display a image on servlet from file upload Your Answer: Hi... reason is inaccessible Thanks Sir, But Servlet page nothing display any type
Display image on JSP page using XML
Display image on JSP page using XML  ... can display a image on JSP page by using XML.  This example will examine how to parse and expose XML information using the JAXP with a JSP page
How display a Image on Servlet from file upload - JSP-Servlet
How display a Image on Servlet from file upload  Dear Sir, My requirement is I want to display a Image on Servlet from File Upload. But It not display on servlet,Its appear a downloaded form and downloaded on disk when click
image display
image display  Hai Friends..... Actually I uploaded filepath into database and image into a folder. Now i want to show that image as my profile photo. How it is?...Friends Can you help me? Thanks in advance to take time
image display
image display  Hai Friends..... Actually I uploaded filepath into database and image into a folder. Now i want to show that image as my profile photo. How it is?...Friends Can you help me? Thanks in advance to take time
display an image on my page
display an image on my page  How can I display an image on my page
Display Blob(Image) from Mysql table using JSP
Display Blob(Image) from Mysql table using JSP In this section, we will display blob data(image) from Mysql database table using JSP code. A Blob stores...;); return; } ADS_TO_REPLACE_6 // display the image
how to display image with listview
how to display image with listview  How can i display the list view with the related images from database
Image display in pdf
Image display in pdf  i am trying to display a image in pdf using xsl fo but " [ERROR] Error while creating area : Error with image URL: images... go through the following link: Display image in pdf
jsp image problem - JSP-Servlet
jsp image problem  hi everyone, How to display multiple images from mysql database to jsp page. please help me
image display - Java Beginners
image display  i need to display all the images from the folder and i dont want give the image path.dynamically it should display. please help  Hi friend, Code to help in solving the problem var
image display - Java Beginners
; %><html><head><title>Retrive Image with jsp</title></head><body><img src="/jsp/red_rose2.gif" name="...;--------------------------------------read for more information,http://www.roseindia.net/jsp/file_upload/Sinle
image in jsp - JSP-Servlet
image in jsp  i m storing path of image in my database.. but when i m trying to display image using that path image is not getting... i m storing path like c:\image\a.jpg ... and i m using tag... how to get
Displaying image using jsp and spring.
Displaying image using jsp and spring.  how to display an image stored in WEB-INF/images folder on the browser using jsp and spring
Display Image in Java
Display Image in Java     ...): Pass the boolean value as true to display the image or Vice-Versa. Here we are passing the boolean value as true to display the image on the frame
How to display date in JSP?
How to display date in JSP?  How to create a simple JSP program which displays date on the page? Thanks
how to display the image in center - Ajax
how to display the image in center  i want to dispaly the image as center of the screen using javascript..while i am clicking the button ..any one give me the code for this one
How to retrieve and display image from database in Java?
on the web page. My application is in Java/JSP. How to retrieve and display image...How to retrieve and display image from database in Java?  Hi, I am.... Please check the it at How to store and retrieve image from database in JSP
J2me image display - Java Beginners
J2me image display  How can i display a jpeg image in j2me  Hi Friend, Please visit the following links: http://www.roseindia.net/j2me/append-image.shtml http://www.roseindia.net/j2me/image-item-example.shtml
Display Java in JSP
Display Java in JSP  please i need urgent help. How can i display Java Applet created in netbeans in JSP?. the Application involves MYSQL Database connection. Thanks
Display Image on JDesktopPane
Display Image on JDesktopPane In this section, you will learn how to retrieve an image from  the database and display it on the JDesktopPane. You can see... != null) { JFrame f = new JFrame(); f.setTitle("Display Image From
How to display date in JSP?
How to display date in JSP?  How to create a simple JSP program which displays date on the page? Thanks   Hi, You should import...() %> Check complete tutorial at How to Create JSP Page? Thanks
Jsp Image prob - JSP-Servlet
Jsp Image prob   I m working on a project i which i have to upload a image in jsp to database and then on next page i will show that image from database so what should i do as i have done first phase
Display both image and data into Swing JTable
Display both image and data into Swing JTable  How To Display both image and data into Swing JTable which is retrieved from MySQL database
java image display - Java Beginners
java image display  How to display images in the folder dynamically with out using database using java and jsp  Hi friend, Code to help in solving the problem var galleryarray=new Array
Image preview - JSP-Servlet
Image preview  How to show the preview of the image when we select the image through browse button in JSP page before storing it in the application... select the image using the file type button i want to dynamically show
Show image and text on same jsp page
Show image and text on same jsp page  Hi all, I have to display image and text on the same jsp page. The text and image are both retrived from mysql database. The image is shown correctly on seperate jsp page but when shown

Ads