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



Home Answers Viewqa JSP-Servlet jsp image display
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


HIMANSHU PANT
jsp image display
0 Answer(s)      a year and 2 months ago
Posted in : JSP-Servlet


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


Advertisement
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
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
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: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
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
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
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
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
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 "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
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
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
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
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
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 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
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
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
display an image on my page
display an image on my page  How can I display an image on my page
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
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; } // display the image response.setContentType("
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
Advertisements
 

 

 

DMCA.com