473,419 Members | 1,605 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

Doesn't displaying image in servlet ?

How can I display Image by servlet using Html <input type="file">, from that path?

Following is my code,I can't proceed further..

Expand|Select|Wrap|Line Numbers
  1. import java.io.BufferedReader;
  2. import java.io.BufferedWriter;
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.io.PrintWriter;
  6. import java.io.StringReader;
  7. import javax.imageio.IIOImage;
  8. import javax.imageio.ImageIO;
  9. import javax.imageio.ImageTypeSpecifier;
  10. import javax.imageio.ImageWriteParam;
  11. import javax.imageio.ImageWriter;
  12. import javax.imageio.metadata.IIOMetadata;
  13. import javax.servlet.ServletException;
  14. import javax.servlet.http.HttpServlet;
  15. import javax.servlet.http.HttpServletRequest;
  16. import javax.servlet.http.HttpServletResponse;
  17.  
  18. /**
  19.  *
  20.  * @author aniketjack
  21.  */
  22. public class ImageReader extends HttpServlet {
  23.  
  24.      BufferedImage image;
  25.     /* * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
  26.      * @param request servlet request
  27.      * @param response servlet response
  28.      * @throws ServletException if a servlet-specific error occurs
  29.      * @throws IOException if an I/O error occurs
  30.      */
  31.     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  32.     throws ServletException, IOException {
  33.         String file = request.getParameter("filechoose");
  34.  
  35.         response.setContentType("image/jpg");
  36.         PrintWriter out = response.getWriter();
  37.         try {
  38.               out.println(""+file);
  39.               BufferedReader br = new BufferedReader(new StringReader(file));
  40.               file = br.readLine();
  41.               File imageFile = new File(file);
  42.                image = ImageIO.read(imageFile);
  43.               //BufferedWriter bw = new BufferedWriter(image);
  44.  
  45.  
  46.  
  47.  
  48.         } finally { 
  49.             out.close();
  50.         }
  51.     } 
  52.  
  53.  
  54.     @Override
  55.     protected void doPost(HttpServletRequest request, HttpServletResponse response)
  56.     throws ServletException, IOException {
  57.         processRequest(request, response);
  58.     }
  59.  
  60.  
  61.  
  62. }

and my HTML code is:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.   <head>
  3.     <title></title>
  4.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5.   </head>
  6.   <body>
  7.       <form action="ImageReader" method="post">
  8.           <input type="file" name="filechoose">
  9.           <input type="submit" name="ShowImage">
  10.       </form>
  11.   </body>
  12. </html>
Jul 21 '10 #1
0 1237

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: midtoad | last post by:
I'm trying to display a GIF image in a label as the central area to a Tkinter GUI. The image does not appear, though a space is made for it. Why is this so? I notice that I can display a GIF...
1
by: Lena | last post by:
I'm having a lot of trouble trying to display an image (CImage) using the CScrollBarView class. I'm using Microsoft Visual C++ .NET (2002), making an MFC Application with these additional specs:...
1
by: Pablo | last post by:
Friends! I have to load an image in a Crystal, but its path must be passed as a parameter or sth like that so as to allow to show a picture dinamically. Example: i have a table 'Personnel', each...
1
by: marwa mohamed | last post by:
i have a databse for archeological sites each with its picture.the pictures are on the server and the path of each pictire is saved in field in the record source table of the report.I used the...
1
by: Zean Smith | last post by:
I am using Visual Source Safe 6.0d, and I created a project then added it to Source Safe using Visual Studio 2003 by right-clicking on the project. When I login to Source Safe, I only see the .cs...
18
by: John | last post by:
Hi I am trying to display an image in a dialog using the following code; Dim frm As New frmImage Dim z As System.Drawing.Bitmap z.FromFile("c:\temp\image.gif") frm.picImage.Image = z...
1
by: basbelgium | last post by:
Hi all, I'm really new at HTML, but I thought it'd be fun to learn... I have an issue whereby, when I post an image in a table cell, it's not displayed... In the left hand cell , all the...
5
by: shreedhan | last post by:
Hey all, I have a strange type of problem. I have a simple code of html (say in test.html) <img src="/home/Shreedhan/edited_shreedhan2.jpg" /> If I put this code in a separate file and...
0
by: tangara | last post by:
Hi, I have tried using Override void doPost (HTTPServletRequest request, HttpServletResponse response) to get data from a html form which states form action = post. However, I can get the data...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.