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.

Similar Messages

  • 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.

  • 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

  • Best practices for image compression in dps

    Hi! I have been reading up on best practices for image compression in dps, and I have read that the source assets of panoramas, image sequences, pan and zoom images, and audio skins are not resampled on upload. So you therefore need to resize them and compress them before dropping them into your article, because dps doesn't do it for you. Okay can do!
    So then Im also reading that the source assets of slideshows, scrollable frames, and buttons ARE resampled as PNG images. Does this mean that DPS will compress them for you when you build the article? So does that mean I shouldn't bother going to the trouble of resizing these images at all? I can just pop in the 15mb 300dpi files used in the print magazine and dps will compress them upon building the article - and this will have no affect on file size?
    And this is also the case with static background images?
    Thanks for your help!

    All images are automatically resampled based on the size of the folio you make. You can drop in whatever resolution image you want, it doesn't matter.
    Neil

  • 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]

  • 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)!

  • 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.

  • Jsp code for report in text or pdf

    How to generate report in either text or pdf format from jsp page?

    How do you want to generate report?
    For pdf you can use itext(http://www.lowagie.com/iText/)..

  • Inserting "if then" code for images

    Hi All,
    I am wanting to do some email marketing and customizing the email to particutlar individuals. ie a female would get a certain image and a male a different one, as well as I have multipule locations that I would like to put their particular store address on.
    I am using an Access Database.
    Feilds are set up with 1's, 2's depending on gender.
    What coding would I use?
    Thanks in advance
    David

    How are you getting the information from this database into ID?
    You probably want to do the logic on the database end. For exmple if you are saving a .csv file from the database, use the if statement to populate a field with the path to one or the other image. Data Merge can use that path info to place an image, and I would expect that xml or one of the catalog plugins could be setup to do the same.

  • Sample JSP Code for SSO

    I'm using 9iAS and 10g. either of the two versions will do. Thanks!
    Russel

    I'm using 9iAS and 10g. either of the two versions will do. Thanks!
    Russel

  • If any one has java code for any video compression algorithm

    i need a complete java code for video compression step by step

    i need a complete java code for video compression step by step

  • 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

  • Java library for JPG Compression

    I have to compress the JPG images with good quality. Please suggest a good java library for image compression.
    Thanks

    Demo:
    import java.awt.*;
    import java.net.*;
    import java.io.*;
    import java.util.*;
    import javax.imageio.*;
    import java.awt.image.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class ImageCompressExample implements Runnable, ChangeListener {
        private BufferedImage original;
        private JLabel compressedLabel;
        private JSlider slider;
        private int byteCount;
        public ImageCompressExample(String url) throws IOException {
            original = ImageIO.read(new URL(url));
        public void run() {
            slider = new JSlider();
            slider.setMajorTickSpacing(10);
            slider.setPaintTicks(true);
            slider.setPaintLabels(true);
            slider.addChangeListener(this);
            compressedLabel= new JLabel();
            updateCompressedLabel();
            JPanel labelPanel = new JPanel(new GridLayout(2,1));
            JLabel originalLabel = new JLabel(new ImageIcon(original));
            originalLabel.setBorder(BorderFactory.createTitledBorder("original image"));
            labelPanel.add(originalLabel);
            labelPanel.add(compressedLabel);
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(labelPanel, BorderLayout.CENTER);
            f.getContentPane().add(slider, BorderLayout.SOUTH);
            f.pack();
            f.setResizable(false);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
        public void stateChanged(ChangeEvent e) {
            if (!slider.getValueIsAdjusting())
                updateCompressedLabel();
        private void updateCompressedLabel() {
            int value = slider.getValue();
            compressedLabel.setIcon(new ImageIcon(compress(original, value/100f)));
            String title = String.format("compression quality = %d%%, bytes = %,d", value,  byteCount);
            compressedLabel.setBorder(BorderFactory.createTitledBorder(title));
        public BufferedImage compress(BufferedImage image, float quality) {
            try {
                Iterator<ImageWriter> writers = ImageIO.getImageWritersBySuffix("jpeg");
                ImageWriter writer = writers.next();
                ImageWriteParam param = writer.getDefaultWriteParam();
                param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
                param.setCompressionQuality(quality);
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                writer.setOutput(ImageIO.createImageOutputStream(out));
                writer.write(null, new IIOImage(image, null, null), param);
                byte[] data = out.toByteArray();
                this.byteCount = data.length;
                ByteArrayInputStream in = new ByteArrayInputStream(data);
                return ImageIO.read(in);
            } catch (IOException e) {
                throw new RuntimeException(e);
        public static void main(String[] args) {
            try {
                String url = "http://www.rsportscars.com/foto/03/carreragt06.jpg";
                EventQueue.invokeLater(new ImageCompressExample(url));
            } catch (IOException e) {
                e.printStackTrace();
    }

Maybe you are looking for