This is my Jsp code for image upload in database:

This is my Jsp code for image upload in database:
-----------Upload.jsp----------------
<html>
<head>
</head>
<body bgproperties="fixed" bgcolor="#CCFFFF">
<form method="POST" action="UploadPicture.jsp" enctype="multiform/form-data">
<%! int update=0; %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.text.*" %>
<%@ page import="java.sql.Date" %>
<%@ page import="java.io.*"%>
<%@ page language = "java" %>
<%
try
String ct="3";
String path;
File image=new File(request.getParameter("upload"));
path=request.getParameter("upload");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:itPlusElectronics","","");
PreparedStatement pstmt=con.prepareStatement("insert into graphics values(?,?,?)");
pstmt.setString(2,path);
pstmt.setString(3,ct);
InputStream is=new FileInputStream(path);
pstmt.setBinaryStream(1, is, (int)(image.length()));
int s=pstmt.executeUpdate();
if(s>0)
out.println("Uploaded");
else
%>
unsucessfull
<%}
is.close();
pstmt.close();
catch(Exception e)
}%>
</p>
<p><br>
<img src="UploadedPicture.jsp">image</img>
<p></p>
</form>
</body>
</html>
My database name is itPlusElectronics and the table name is "graphics".
I have seen as a result of the above code that the image is stored in database as "Long binary data". and database table is look like as follows-------
picture path id
Long binary data D:\AMRIT\1-1-Picture.jpg 3
To retrive and display i use this JSP code as--
------------------------UploadedPicture.jsp------------------------------
<html>
<head>
</head>
<body bgproperties="fixed" bgcolor="#CCFFFF">
<%! int update=0; %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.text.*" %>
<%@ page import="java.io.*"%>
<%@ page language = "java" %>
<%@page import="javax.servlet.ServletOutputStream"%>
<%
try
String path;
path=request.getParameter("upload1");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:itPlusElectronics","","");
PreparedStatement pst = con.prepareStatement("SELECT * FROM graphics WHERE id ='3'");
// pst.setString(3, id);
ResultSet rs = pst.executeQuery();
path=rs.getString("path");
if(rs.next()) {
byte[] bytearray = new byte[4096];
int size=0;
InputStream sImage;
sImage = rs.getBinaryStream(1);
response.reset();
response.setContentType("image/jpeg");
response.addHeader("Content-Disposition","filename=path");
while((size=sImage.read(bytearray))!= -1 )
response.getOutputStream().write(bytearray,0,size) ;
response.flushBuffer();
sImage.close();
rs.close();
catch(Exception e)
%>
</body>
</html>
Now after browsing a jpg image file from client side and pressing submit button ;
I am unable display the image in the Upload.jsp file.Though I use
<img src="UploadedPicture.jsp">image</img> HTML code in Upload.jsp
file .
Now I am unable to find out the mistakes which is needed for displaying the picture in the Upload.jsp page..
If any one can help with the proper jsp code to retrive and display the image ,please please help me !!!!!!!!!!!!!!!!!!!!!!!!!!

dketcham wrote:
cotton.m wrote:
>
2) I'm looking at how you called stuff, and you're trying to call the jsp file as an image? That jsp isn't the source of the image, just a page linking to an image. I think if you really want to do things that way you're going to need to just include that jsp within the jsp you're calling it from (or you can do it the easy way, and if you have the information to get the path of the image you want, you could simply call the image from the first jsp you posted)This is incorrect.
There are two JSPs. The second when called will (if it worked) return the source of an image as stored in the database.even when called with <img src=xx.jsp>??
Yes.
If any of what I say next seems obvious or otherwise negative I apologize, just trying to explain and I don't know what you know vs what you don't.
The link in the src is just a URL not a filetype. So just because it ends with JSP does not mean it has to return HTML. The content type is determined by the browser using the Content-Type header returned by the server in the HTTP response. In this case the header is set to be a jpeg so that's what the browser will attempt to interpret the content part of the response as.
So in fact one is not limited to just HTML or images but whatever content type you would like to return (that the browser can understand anyway). This could be HTML or it could be an image of some type or it could be a PDF or it could be an Excel spreadsheet. All you have to do in the JSP is set the header appropriately and then send content that is actually in that format.
This does not just apply to JSP by the way but all other web programming languages. You can do similar things to produce the same results in PHP, Perl, ASP etc.
The only JSP/Servlet complication is whether or not doing this in a JSP is a "good" idea but I am not an expert enough at that to make a definitive statement. Mostly though JDBC in a JSP is a no-no.

Similar Messages

  • Jsp code for image compression

    Hai,sir this is surendra i am doing a project using jsp and mysql.
    In that each user can put his image and i am storing that image in mysql blob but that results to that database size.
    So i need jsp code for image compression or another way for storing images.

    There's no need to store images in db. You may store them in a dedicated folder.

  • On file open: "This document contains JavaScript code for a widget that no longer exists."

    I had an existing, functional datepicker in a web page.
    Recently I downloaded the UI Datepicker in the Widget Browser and installed it in DW CS5. Now every time I load the file that calls the datepicker that I added myself, a warning opens with the following text:
    This document contains JavaScript code for a widget that no longer exists. If you don't remove the code, the browser might display JavaScript errors when loading the page. Would you like Dreamweaver to find all instances of this code for you?
    Widget: $("#reservDateBegin").datepicker();
    Widget: $("#reservDateEnd").datepicker();
    Clicking "Yes" opens the file and shows the search box at the bottom of the window with [current document] in File and $("#reservDateEnd").datepicker(); in Matched Text. Clicking "No" just opens the file.
    The error is wrong, since installing the widget is what caused the error in the first place!
    How can I get DW to stop showing this message?
    Thanks for any help.

    I do understand you're trying to be helpful. I was just hoping providing the relevant code snippets would be sufficient so I didn't have to take the time to provide a "cleaned" version of the files and upload those to a public-safe location.
    Zabeth69 wrote: If you don't understand what 'code at the bottom of the page' means, you have not used one of those systems. I don't know what causes the error code to come up (besides removing a Spry widget, I mean). So if it doesn't apply to you, ignore it.
    This is exactly my point: I haven't used any of the DW "systems". I've always manually coded in DW, so I can't have removed a Spry widget in the first place. It wasn't until I installed the Widget using the Widget Browser that I started getting the error (I don't mean adding the datepicker widget to the code using the DW Insert menu - I mean installing the Widget into DW itself). Ignoring such an erroneous/incorrect error seems kind of silly, since every time I open the file I get the error message.
    Anyway, as requested, the following are links to the contactUsCleaned.php page, and the php included headerCleaned.php file. Since these use php includes to complete the rendered HTML, they won't look right in the browser, but as you know viewing the source will show the relevant html, javascript, and jquery code. I didn't see any way to upload the files in this forum, which, due to the php code, would be preferable to see exactly what my code looks like...
    http://www.eventidewebdesign.com/public/contactUsCleaned.php
    http://www.eventidewebdesign.com/public/headerCleaned.php
    The footer.php file the contactUs page includes is simply a set of HTML links to the pages on the site, copyright info, and the Google Analytics script. There is no other code in the footer.php file.

  • JSP codes for running a JAVA program

    hello...
    does anyone know the JSP codes for running a Java program from my web page?? i mean i already have my java program compiled... and i just want this java program to run in the background when I click on a button or a link...
    Any idea about this?
    plz advice..
    avi

    yes... u r somewhat right... but this runs on Jakarta Tomcat...
    i'm using the Apache Http Server together with the ServletExec AS which enable the Apache server to run JSP..
    I've created a package where i've put my classes...
    WEB-INF/classes/tbd(package name)/my classes
    and i've added.. package name.. in my java program..
    and then in jsp... i've written..
    <%@ page import="tdb.*"%>
    <jsp:useBean id="exec" class="tdb.textdb" />
    <%exec.convert_data();%>
    but when i run the page it says the package does not exist...
    can anyone tell where to place the folder WEB-INF so that it can run fine?
    thx
    avi

  • Jquery or code for Image loading on Sp Gridview Pager(Next ,Prev) click functionality on sharepoint 2010

    Jquery or dynamic code for Image loading on Sp Gridview Pager(Next ,Prev) click functionality on sharepoint 2010.
    i have a dynamic SP gridview contains Previous and next
    buttons for paging.
    page doesn't contain Update panel.
    grdXRPSUsers.PagerSettings.Mode = PagerButtons.NextPrevious;
    grdXRPSUsers.PagerSettings.PreviousPageText = "< Previous Page";
    grdXRPSUsers.PagerSettings.NextPageText = "Next Page >";
    grdXRPSUsers.PagerSettings.FirstPageText = "First Page";
    grdXRPSUsers.PagerSettings.LastPageText = "Last Page";
    When i click on Next or Previous page in the gridview it will take more time and showing progress bar in th below.
    As per my client request, i need to change the
    progress bar to Loading image (Wheel at middle of the grid at fething time).
    How its possible either through jquery or Programming(code behind).
    Please help

    Hi,
    According to your description, my understanding is that  you want to add loading image when click the paging button to load the data.
    I suggest you can use Jquery BlockUI Plugin to show a block image when loding data in paging click event.
    Here is a similiar thread for your reference:
    How to display a loading image until a gridview is fully loaded
    More information:
    Jquery BlockUI Plugin
    Thanks
    Best Regards
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • JSP Code to connect Oracle 10g Database

    Can some give the JSP code for connecting Oracle 10g database

    hi
    First u have to get ojdbc1.4.jar file ,,,, it is the driver for the oracle
    then use the following code :
    import java.sql.*;
    import java.util.*;
    public class connectionBean
         Connection con;
         Statement statement;
         connectionBean()
              try
            Class.forName("oracle.jdbc.driver.OracleDriver");
            con = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:Xe","hr","hr");
            statement=con.createStatement();
              catch(Exception cnfe){     }
         public void testMethod()throws  SQLException{
              ResultSet rs=statement.executeQuery("select * from COUNTRIES");
              while(rs.next())
              System.out.print(rs.getString(1));
         public static void main (String args[])throws  SQLException
              connectionBean cb=new connectionBean();
              cb.testMethod();
    }hope this will help
    Good luck
    Mohammed

  • Max Size for Image Upload

    Hi Frenz,
    I am planning to use Oracle AppEx's file upload functionality to upload image to DB. I would like to know
    Is there any size limitation for Image to be uploaded. Ex: can't exceed more that ! MB?
    Does it support all types of Image format like JPG, BMP.
    Will be Using a third party reporting tool to generate roprts.
    So need to know how fast is the retrival process from backend.
    (Am aware this is not a Oracle AppEx related question!! But incase if any use this in your projects !!)

    The following parameters should be used
    org.apache.myfaces.trinidad.UPLOAD_MAX_MEMORY
    org.apache.myfaces.trinidad.UPLOAD_MAX_DISK_SPACE
    Instead of
    oracle.adf.view.faces.UPLOAD_MAX_MEMORY
    oracle.adf.view.faces.UPLOAD_MAX_DISK_SPACE
    Please check the following post:
    ADF file upload size
    Thanks,
    Navaneeth

  • Help Needed with HTML code for Image Positioning

    Hi All,
    Need a little help with some code for positioning images.
    I initially used the following:
    This is fine, but the border automatically puts a black border around the photo - how do I change it to white? Is there a way to set margins too, to prevent the text butting up against the photo?
    I also used the following code with success:
    <style type="text/css"
    img
    float:right;
    border:2px solid white;
    margin: 0px 0px 15px 20px
    </style>
    This code works, however the problem with it is it is not individual to just one photo - it moved all my photos and on that page, I wanted one photo floated to left and another to the right.
    If I use this code, how can I make it photo specific, so that it only affects the placement, margins and borders of one photo?
    Any help would be great.
    Thanks

    CSS question, not iWeb question. Regardless, use inline CSS styling for the image. You can also wrap the image in its own tag and declare an id or simply declare an id for the img tag, then set the style for the id_name:
    <style type="text/css"
    img#id_name
    float:right;
    border:2px solid white;
    margin: 0px 0px 15px 20px
    </style>
    If you want to control the style of more than one image on a page but not all then use a class instead of an id.
    the border automatically puts a black border around the photo - how do I change it to white? Is there a way to set margins too, to prevent the text butting up against the photo?
    I believe you have discovered a solution for this according to your CSS code. You have set the border to white by looking at the code and adjusting it appropriately. Your margin is declared in the CSS also, adjust the pixels appropriately.
    Read up some more on CSS to educate yourself further. I suggest w3schools.com or a CSS forum instead of the iWeb forum if you have CSS questions. It's kind of like if you drive your auto to the supermarket so you decide to go to the supermarket and ask everyone in the produce section to help when you have car problems. All the supermarket does is provide a place to park your auto. If you have car problems then ask a mechanic. iWeb (and most of its users) doesn't specialize in code, it simply provides an area for you to place it. Granted you might get lucky and find a mechanic in the produce section of the supermarket, but you're more likely to find a specialist at an auto swap meet (or CSS coding forum)!

  • This is it ! Code for Full Screen Camera STEP bySTEP idiot prove !

    1: Create a Normal View Based Application
    2: Drag in "BTLFullScreenCameraController" *.h and *.m files into Xcode.
    3: In the Header file, implement this:
    #import "BTLFullScreenCameraController.h"
    4: Add in the delegations <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
    UIView *BaseView; //Base View that everything else adds to.
    BTLFullScreenCameraController *camera; //The Magic
    UIImageView *LCARS_Frame; //The ImageView that frames the whole camera [LCARS Frame]
    UILabel *label; //Labels and more labels [Possibly the information tags]
    @property (nonatomic, retain) UIView *BaseView;
    @property (nonatomic, retain) BTLFullScreenCameraController *camera;
    @property (nonatomic, retain) UIImageView *LCARS_Frame;
    @property (nonatomic, retain) UILabel *label;
    //Camera Initialization
    - (void)initCamera;
    - (void)startCamera;
    5: In the *.m File:
    On the of the @implementation file, add this:
    #define OVERLAY_ALPHA 0.50f
    @synthesize BaseView;
    @synthesize camera;
    @synthesize LCARS_Frame;
    @synthesize label;
    - (void)loadView
    self.navigationController.toolbarHidden = YES;
    self.navigationController.navigationBarHidden = YES;
    [UIApplication sharedApplication].statusBarHidden = YES; //This code remove the time and battery indicator top bar.
    self.BaseView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; //You need to Rect the BaseView to take up the battery indicator's space.
    self.BaseView.opaque = NO; //This somehow affects the LCARS Frame image that will be super imposed on top by allow the next line to work.
    self.BaseView.alpha = OVERLAY_ALPHA; //This line can only work after the previous line.
    //Add Image First
    LCARS_Frame = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"binocs.png"]] autorelease];
    [self.BaseView addSubview:LCARS_Frame];
    //Then Label, else label will be under the opacity of the image and get darker.
    label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
    label.text = @"AR Up";
    label.textAlignment = UITextAlignmentCenter;
    label.adjustsFontSizeToFitWidth = YES;
    label.textColor = [UIColor redColor];
    label.backgroundColor = [UIColor darkGrayColor];
    label.shadowOffset = CGSizeMake(0, -1);
    label.shadowColor = [UIColor blackColor];
    [self.BaseView addSubview:label];
    self.view = self.BaseView; //Set BaseView as the default view.
    [super viewDidLoad];
    //Just copy and paste this code, it will work.
    -(void) viewDidAppear:(BOOL)animated
    [self initCamera];
    [self startCamera];
    - (void) initCamera {
    if ([BTLFullScreenCameraController isAvailable]) {
    NSLog(@"Initializing camera.");
    BTLFullScreenCameraController *tmpCamera = [[BTLFullScreenCameraController alloc] init];
    [tmpCamera.view setBackgroundColor:[UIColor blueColor]];
    [tmpCamera setCameraOverlayView:self.view];
    tmpCamera.overlayController = self;
    #ifdef BTLINCLUDE_IMAGESHARING
    BTLImageShareController *shareController = [[BTLImageShareController alloc] init];
    shareController.delegate = self;
    [self.view addSubview:shareController.view];
    tmpCamera.shareController = shareController;
    #endif
    self.camera = tmpCamera;
    [tmpCamera release];
    } else {
    NSLog(@"Camera not available.");
    - (void)startCamera {
    // TODO: figure out why simply setting the view is not working
    // since the modal view is not as desirable
    // This isn't working but should:
    //self.view = self.camera.view;
    // Modal view always works, but it's harder to work with.
    [self.camera displayModalWithController:self animated:YES];

    1) Use, this can be done, as you said in 1.4 there is Full Screen mode for windows.
    2) There is no way to catch Alt-Tab. It would too dangerous to allow to catch it and prevent. All you can do is to react on it, I am sure you'll receive some focus event(DEACTIVATE, WINDOW_LOST_FOCUS, FOCUS_LOST) when user switches from your application by Alt-Tab
    3) There is no way to prevent screen capture, it is system call, I am sure you can write some C application using hooks to catch and filter out key sequence for screen capture but not in Java.

  • MultipartParser vs MultipartRequest for Image Upload

    We are facing a weird issue. We were using MultipartParser for all our file uploads till now. We now need to upload image files and we are facing issues. We came across various knowledge base articles that said we can't upload an image using MultipartParser.
    If that is true, has anyone used MultipartRequest and have got the image uploaded to the server?
    Once the image is uploaded we need to create a thumbnail out of it. We are using javax.imageio.* package to do that.
    Any help is appreciated.

    If that is true, has anyone used MultipartRequest and
    have got the image uploaded to the server?
    Unless you're using Creator 2004Q2, you should take a look at the file upload component included with Creator 2.
    Best regards.
    Antonio.

  • Code for the updating the database

    Can anyone send required code(EO,VO,CO) to update a row in the database table.
    I have tried the code in the turorial example. but i am not getting.

    i am getting this error while updating a column value in a database
    oracle.apps.fnd.framework.OAException: java.lang.IndexOutOfBoundsException: Index: 8, Size: 8
    at oracle.apps.fnd.framework.OAException.wrapperInvocationTargetException(OAException.java:972)
    at oracle.apps.fnd.framework.server.OAUtility.invokeMethod(OAUtility.java:210)
    at oracle.apps.fnd.framework.server.OAUtility.invokeMethod(OAUtility.java:132)
    can anyone help.

  • Code for image swap of sprite images that works on retina screens (@2x)

    Hello,
    I'm having difficulty finding code (javascript, jquery or css) that will successfully swap-out lower-res sprite images for higher-res sprite images "@2x" intended for retina screens. I'm using DWCC/HTML5/CSS3. Can anyone make a recommendation?
    Thanks for your help!

    Does this help you?
    http://css-tricks.com/snippets/css/retina-display-media-query/
    Nancy O.

  • Code for image shadow effect

    iWeb creates very nice shadows. Is it a separate image created on the fly or some javascript? Is there any way to get the code that generates that effect? I'd like to extend it to other pages that weren't made in iWeb.
    Thanks in advance.
    Mike

    OK. Here's the solution for anyone interested. A couple of warnings first though: Apple has a naming scheme with the shadows. If you rename "shadow_1" to "shadow_pocket", for example (even if you change it in the HTML file too, it won't work.
    If you saw the code I posted last time, you know how to use one type of shadow. The code below is a javascript file that allows 3 different shadows. Be careful to put braces and parenthesis in the right places. Javascript is a very sensitive language. You can use divs to enclose the images you want to add the shadow effect to. The divs need to have class="tinyText shadow_X", where X is the kind of shadow you want.
    On to the offset… This was actually very easy. It is found in the Javascript below "IWPoint(0.0000,1.0000)". In that example, it literally means that the shadow is offset 1 pixel downward and no horizontal offset. It's a simple (x,y) coordinate system where x and y are the pixel increments from the original image.
    The Javascript code:
    setTransparentGifURL('Media/transparent.gif');function applyEffects()
    {var registry=IWCreateEffectRegistry();registry.registerEffects({shadow_1:new IWShadow({blurRadius:2,offset:new IWPoint(0.0000,1.0000),color:'#000000',opacity:1.000000}),shadow_2:new IWShadow({blurRadius:5,offset:new IWPoint(0.0000,2.0000),color:'#000000',opacity:1.000000}),shadow_0:new IWShadow({blurRadius:5,offset:new IWPoint(0.0000,2.0000),color:'#000000',opacity:1.00000})});registry.applyEffect s();}
    function hostedOnDM()
    {return false;}
    function onPageLoad()
    {loadMozillaCSS('Blank_files/BlankMoz.css')
    fixAllIEPNGs('Media/transparent.gif');applyEffects()}
    Apple has done incredible work on these JavaScript libraries. So, anyone that wants to add beautiful shadows to their images will find these posts helpful.
    Thanks for your help too Old Toad.
    Mike

  • JSP code for Alarm

    Hi i need to create an Alarm UI in JSP page. Like what Time CPU,Memory ,concurrent value goes above the marked value(90% usage) should be highlight in different colour like Red. All this data are stored on Oracle database. need to show in an JSP Can some one provide code similar to that thanks

    Saish wrote:
    http://www.google.com/search?q=java+socket+tutorial
    The very first result that came up was Sun's tutorial on sockets: http://java.sun.com/docs/books/tutorial/networking/sockets/
    Writing these in a JSP is generally no different than doing so in Java source file, except you will need to surround the Java code with JSP scriptlet tokens: http://www.jsptut.com/Scriptlets.jsp
    However, I would advise instead writing the socket code in a regular Java object and then invoking that from your JSP. You really don't want to have code in the JSP if you can help it.
    - SaishYou advise to use scriptlets. You know you will have to spend a year or two in purgatory for that!
    Be cool, use a servlet for this.

  • While recording a t.code for lsmw upload

    How to obtain data collection template from LSMW object for example BOM creation.  I forgot this step.  Can some one help.

    Dear,
    LSMW-> 1 Maintain Object Attributes  --> Flag on Batch input recording --> insert name and t-code in order to start registration.
    Let me know if i solved your dubt.
    Daniele

Maybe you are looking for

  • Itunes PC instalation - error 7 (windows error 5) ... HELP please

    Its been 2 months now and i think i have exhausted all avenues - fresh input would be very good please.

  • What printers are compatible with Lion?

    I am on my second printer, and no dice with HP officejet 4500. Are there any printers that are compatible with Lion, and easy to install. It has been nothing but a nightmare, and a financial burden to try to find a printer that works. please advise,

  • IPhoto Duplicates images?

    I'd like to start using iPhoto but I've always hated the idea that it creates duplicates of my images just so that it can store them in it's own weird file system. I want my photos to stay where they are on my hard drive and I don't want to bloat my

  • Navigation within a subdirectory

    I'm not new to Flash, but am doing something I haven't tried before. I am creating a store using a Flash navigation bar in the header for just a few of the categories. But enough of that ... Here is the deal. The Flash nav works great on the main pag

  • HT1222 how do i update my iphone 3 ??

    i have an iphone 3 an carnt update it. how do i do it ??