Home Answers Viewqa Java-Beginners how to send and retrieve image along with text to and from database

 
 


dwighttaylor
how to send and retrieve image along with text to and from database
0 Answer(s)      a year and 3 months ago
Posted in : Java Beginners

im using app engine and i have two logics from different sources and i want to combine them. ive used the greeting example from app engine and i have a random image generator. im so stumped right now and i dont know how to combine the two. i want to take the random image along with the text and send it to another user for work. the application takes a random image for which code i have along with text that the user fills out based on the writing exercise about the random image and on the post it sends the data to another user. i hope im explaining this correctly

this is app engines greeting application

package guestbook;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

import java.io.IOException;
import java.util.Date;
import java.util.logging.Logger;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SignGuestbookServlet extends HttpServlet {
    private static final Logger log =
            Logger.getLogger(SignGuestbookServlet.class.getName());

    public void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {
        UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();

        // We have one entity group per Guestbook with all Greetings residing
        // in the same entity group as the Guestbook to which they belong.
        // This lets us run an ancestor query to retrieve all Greetings for a
        // given Guestbook. However, the write rate to each Guestbook should be
        // limited to ~1/second.
        String guestbookName = req.getParameter("guestbookName");
        Key guestbookKey = KeyFactory.createKey("Guestbook", guestbookName);
        String content = req.getParameter("content");
        Date date = new Date();
        Entity greeting = new Entity("Greeting", guestbookKey);
        greeting.setProperty("user", user);
        greeting.setProperty("date", date);
        greeting.setProperty("content", content);

        DatastoreService datastore =
                DatastoreServiceFactory.getDatastoreService();
        datastore.put(greeting);

        resp.sendRedirect("/guestbook.jsp?guestbookName="
                + guestbookName);
    }
}

//the guestbook.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="com.google.appengine.api.datastore.DatastoreServiceFactory" %>
<%@ page import="com.google.appengine.api.datastore.DatastoreService" %>
<%@ page import="com.google.appengine.api.datastore.Query" %>
<%@ page import="com.google.appengine.api.datastore.Entity" %>
<%@ page import="com.google.appengine.api.datastore.FetchOptions" %>
<%@ page import="com.google.appengine.api.datastore.Key" %>
<%@ page import="com.google.appengine.api.datastore.KeyFactory" %>

<html>
  <head>
    <link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
  </head>

  <body>
<DIV id="container">
<DIV id="left">
<%
    String guestbookName = request.getParameter("guestbookName");
    if (guestbookName == null) {
        guestbookName = "default";
    }
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    if (user != null) {
%>

<p>Hello, <%= user.getNickname() %>! (You can
<a href="<%= userService.createLogoutURL(request.getRequestURI()) %>">sign out</a>.)</p>
<%
    } else {
%>
<p>Hello!
<a href="<%= userService.createLoginURL(request.getRequestURI()) %>">Sign in</a>
to include your name with greetings you post.</p>
<%
    }
%>


<%
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    Key guestbookKey = KeyFactory.createKey("Guestbook", guestbookName);
    // Run an ancestor query to ensure we see the most up-to-date
    // view of the Greetings belonging to the selected Guestbook.
    Query query = new Query("Greeting", guestbookKey).addSort("date", Query.SortDirection.DESCENDING);
    List<Entity> greetings = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(5));
    if (greetings.isEmpty()) {
        %>
        <p>Guestbook '<%= guestbookName %>' has no messages.</p>
        <%
    } else {
        %>
        <p>Messages in Guestbook '<%= guestbookName %>'.</p>
        <%
        for (Entity greeting : greetings) {
            if (greeting.getProperty("user") == null) {
                %>
                <p>An anonymous person wrote:</p>
                <%
            } else {
                %>
                <p><b><%= ((User) greeting.getProperty("user")).getNickname() %></b> wrote:</p>
                <%
            }
            %>
            <blockquote><%= greeting.getProperty("content") %></blockquote>
            <%
        }
    }
%>
</DIV>
<DIV id="right">
<form action="/sign" method="post" style="width: 552px; ">
      <div><textarea name="content" rows="3" cols="60"></textarea></div>
      <div><input type="submit" value="Post Greeting"></div>
      <input type="hidden" name="guestbookName" value="<%= guestbookName %>">
    </form>
    </DIV>
    </DIV>    
  </body>
</html>

/*random image generator

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<style type="text/css">
html,body {
height:100%;
margin:0;
padding:0;
}
#imlocation {
width:100%;
height:100%;
border:3px double #999;
margin:2% auto;
}
#imlocation img {
width:100%;
height:100%;
}
</style>

<body>

<div id="imlocation" align="right">

<script type="text/javascript">
<!--
 var imlocation = "images/forest/";
 var currentdate = 0;
 var image_number = 0;
 function ImageArray (n) {
   this.length = n;
   for (var i =1; i <= n; i++) {
     this[i] = ' '
   }
 }
 image = new ImageArray(61)
 image[0] = 'img0.jpg'
 image[1] = 'img1.jpg'
 image[2] = 'img2.jpg'
 image[3] = 'img3.jpg'
 image[4] = 'img4.jpg'
 image[5] = 'img5.jpg'
 image[6] = 'img6.jpg'
 image[7] = 'img7.jpg'
 image[8] = 'img8.jpg'
 image[9] = 'img9.jpg'
 image[10] = 'img10.jpg'
 image[11] = 'img11.jpg'
 image[12] = 'img12.jpg'
 image[13] = 'img13.jpg'
 image[14] = 'img14.jpg'
 image[15] = 'img15.jpg'
 image[16] = 'img16.jpg'
 image[17] = 'img17.jpg'
 image[18] = 'img18.jpg'
 image[19] = 'img19.jpg'
 image[20] = 'img20.jpg'
 image[21] = 'img21.jpg'
 image[22] = 'img22.jpg'
 image[23] = 'img23.jpg'
 image[24] = 'img24.jpg'
 image[25] = 'img25.gif'
 image[26] = 'img26.jpg'
 image[27] = 'img27.jpg'
 image[28] = 'img28.jpg'
 image[29] = 'img29.jpg'
 image[30] = 'img30.jpg'
 image[31] = 'img31.jpg'
 image[32] = 'img32.jpg'
 image[33] = 'img33.jpg'
 image[34] = 'img34.jpg'
 image[35] = 'img35.jpg'
 image[36] = 'img36.jpg'
 image[37] = 'img37.jpg'
 image[38] = 'img38.jpg'
 image[39] = 'img39.jpg'
 image[40] = 'img40.jpg'
 image[41] = 'img41.jpg'
 image[42] = 'img42.jpg'
 image[43] = 'img43.jpg'
 image[44] = 'img44.jpg'
 image[45] = 'img45.jpg'
 image[46] = 'img46.jpg'
 image[47] = 'img47.jpg'
 image[48] = 'img48.jpg'
 image[49] = 'img49.jpg'
 image[50] = 'img50.jpg'
 image[51] = 'img51.jpg'
 image[52] = 'img52.jpg'
 image[53] = 'img53.jpg'
 image[54] = 'img54.jpg'
 image[55] = 'img55.jpg'
 image[56] = 'img56.jpg'
 image[57] = 'img57.jpg'
 image[58] = 'img58.jpg'
 image[59] = 'img59.jpg'
 image[60] = 'img60.jpg'
 var rand = 60/image.length
 function randomimage() {
    currentdate = new Date()
    image_number = currentdate.getSeconds()
    image_number = Math.floor(image_number/rand)
    return(image[image_number])
 }
 document.write("<img src='" + imlocation + randomimage()+ "'>");
//-->
</script>
</div>
</body>
</html>

what i want it to do is send the random image along with the text to the database if the user presses the button. thanks im hoping for an answer

View Answers









Related Pages:
how to send and retrieve image along with text to and from database
how to send and retrieve image along with text to and from database  .... i want to take the random image along with the text and send it to another user...;/body> </html> what i want it to do is send the random image along
How to retrieve image from database
How to retrieve image from database  hi........ How to retrieve image from database when it is stored. I have stored image in postgresql and want to retrieve in java form. Can u tel me hw to do? I am trying n able to do also
how to store and retrieve image from database
how to store and retrieve image from database  how to store and retrieve images into database(oracle) and how to retrive images from database using jsp   Here is a jsp code that insert and retrieve image from mysql
Image retrieve
Image retrieve  HI.. store image path/data Java Coding. ... It's supposed to take the image, store it in a directory as well as pass the image path to mysql database... Now I want to retrieve the data from directory using path
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
how we retrieve image from database
how we retrieve image from database  my code is:- $search=$_POST...;lt;/table&amp;amp;gt;"; mysql_close($con);   PHP retrieve image from mysql database: <?php mysql_connect("localhost","username","password
how to retrieve images from database to jsp?
how to retrieve images from database to jsp?  Hi sir,i want to stores images along with the name and price with database and retrieve it on jsp.and...(); String strQuery = "select image from data where id="+id; ResultSet rs
<img src=""> using retrieve image from database using jsp
using retrieve image from database using jsp  how to <img src="" > tag using retrieve image from database and display in jsp
To retrieve image from SQL Server Database - Java Server Faces Questions
To retrieve image from SQL Server Database  Sir/Madam, I am trying to retrieve image from SQL Server 2000 database in Visual Web JSF Page using... or in Image Component. please help me in retrieving and displaying image from SQL Server
Retrieve image from mysql database through jsp
Retrieve image from mysql database through jsp... to retrieve image from mysql database through jsp code. First create a database...' of database 'mahendra'. Structure of table 'save_image' First create database named
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve image from mysql database using java and show it in HTML img tag ?
how to retrieve image from mysql database using java and show it in HTML img tag ?  how to retrieve image from mysql database using java and show it in HTML img tag
how to store and then immediately retrieve when store the image into database?
how to store and then immediately retrieve when store the image into database?  how to store and then immediately retrieve when store the image into database?   Here is a jsp code that insert and retrieve image from
how to retrieve image from mysql using java - Java Beginners
how to retrieve image from mysql using java  hi i am using jsf and java IDE netbean,database mysql.how to retrieve image from mysql database. please help me   Hi friend, I am sending you a link. I hope
Insert and Retrieve Image - JSP-Servlet
Insert and Retrieve Image  Hello, I need source code using java servlet or jsp and html form and brief explanations on how to insert and retrieve image from Microsoft sql database 2000 not Mysql please as sent to me earlier
how to insert and retrieve an image from mysql using java - Java Beginners
how to insert and retrieve an image from mysql using java  how to insert and retrieve an image from mysql using java?  Hi friend, Code... data and image from specified address. */ int s
Retrieve date from MYSQL database
Retrieve date from MYSQL database In this tutorial, you will learn how to retrieve date from database. Storing and Retrieving dates from the database... created a database connection and using the Statement interface, we have send
How To Retrieve Image From From MySQL Using Java
How To Retrieve Image From From MySQL Using Java In this section we will discuss about how to retrieve image from the MySQL using Java. This example explains you about all the steps that how to retrieve image from MySQL database
image retrieve - Java Beginners
Image Retrieve  How to retrieve the image from mysql field using java
Retrieve image from database using Servlet
Retrieve image from database using Servlet     ... that connects to the MySQL database and retrieves the image from the table. After... applications that retrieves the image from database. You can use this type
retrieve from database........
retrieve from database........  <p>hi i am not able to retrieve string from database to a text box in web page my code is as follows:-</p> <p>&lt;HTML> <link rel="stylesheet" type="text/css" href
Retrieving the Image from a database Table
to retrieve the image from the database table. You can do it very easily after... will help us to retrieve the image from the database. The ResultSet obiect...Retrieving the Image from a database Table Consider a case where we want
how to use bean to retrieve data from database
how to use bean to retrieve data from database  how to use bean to retrieve data from database   poda sendru
retrieve value from db in text box + calendar implementation.
retrieve value from db in text box + calendar implementation.  I... there is already a text box..Now i want to get the value retrieved from database in that text field how can i do it... Please help...   Please visit
retrieve the data to text fields from database on clicking the value of combo box
retrieve the data to text fields from database on clicking the value of combo box   retrieve the data to text fields from database on clicking... getting data into textarea from database table by clicking on the button
image retrive into DataBase - JDBC
shows you how to retrieve image from database using a servlet and then show..., Retrieving image from database is easy task. JDBC provides all the necessary API and function to retrieve the image from database. You retrieve image from database
Upload and display image and text records using JSP and Oracle
from database. But i couldnot retrieve and display image. I want to store the image ( uploaded by the user) and retrieve it along with the other records. Please...Upload and display image and text records using JSP and Oracle  Hi
image in database
image in database  how to set image in database and retrieve it using servlet(java)in msaccess
retrieve data from database with hyperlink
retrieve data from database with hyperlink  sir....i have one table called 'name' having two values i have to retrieve those data with a hyperlink and show in browser and if we click hyperlink its shows his sub categories....how
Fetching image from database
Fetching image from database  I have uploaded image path and image name in database so, now how can i display that image using JSP or HTML page... in database is:E:\1003\54175\20110407121554 image name i have stored
Write records into text file from database
Write records into text file from database You have already learnt how to insert records from text file to database. But here we are going to retrieve records from database and store the data into the text file. For this purpose, we have
how to store image upload path to mssql database
how to store image upload path to mssql database  hi there!!, i need help in storing the image upload path into the database. basically i just use file select to upload the image from jsp to database. however when i click submit
how to store image upload path to mssql database
how to store image upload path to mssql database  hi there!!, i need help in storing the image upload path into the database. basically i just use file select to upload the image from jsp to database. however when i click submit
how to store image upload path to mssql database
how to store image upload path to mssql database  hi there!!, i need help in storing the image upload path into the database. basically i just use file select to upload the image from jsp to database. however when i click submit
how to store image upload path to mssql database
how to store image upload path to mssql database  hi there!!, i need help in storing the image upload path into the database. basically i just use file select to upload the image from jsp to database. however when i click submit
How to send the data selected from drop down menu from html page to sql 2005 database.
How to send the data selected from drop down menu from html page to sql 2005 database.  Dear Sir, If I want to save the information provided... system ,how can I save these data in database and how to retrieve later .Thanks
Retrieve data from the database and write into ppt file
Java Retrieve data from the database & write into ppt file In this section, we are going to retrieve data from the database and write into the .ppt file... in a PowerPoint Document which allows to access the text and the layout
Data retrieve from mysql database
Data retrieve from mysql database  Hi sir, please give some example of jsp code for retrieving mysql database values in multiple dropdown list... text field using struts and hibernate. Regards Subrat   The given
how to text send from list to textbox - Swing AWT
how to text send from list to textbox  dear sir/madam I whant to send text from list to textbox. plz give me solution for this problem.   Hi friend, Plz explain the problem in details to solve it and specify
store and retrive image from database - JDBC
()); } } } For retrieve image from database visit to : http...store and retrive image from database  how to store and retrive an image in database using java?  Hi friend, Code for store image
how to upload image from jsp to mssql
how to upload image from jsp to mssql  hi there!!, i'm using jsp and servlet to upload images to the database. however i have difficulty in uploading database. hope u can help in my database: i have imagetbl that contain image
how to upload image from jsp to mssql
how to upload image from jsp to mssql  hi there!!, i'm using jsp and servlet to upload images to the database. however i have difficulty in uploading database. hope u can help in my database: i have imagetbl that contain image
How to copy text from a gif image
How to copy text from a gif image  I have some gif images that containing some important text. i want to have that text in my notepad file. i have.... so, please tell me how can i copy that text to my notepad. i am using ubuntu
Text Editor Image upload
Text Editor Image upload   how to browse an image from text editor instead of giving url of particular image using javascript
using getText() to retrieve text from an array of text fields with loop.
using getText() to retrieve text from an array of text fields with loop.  ... presses button. Now I want to get the text from all the textfields using array.......so I want to know how can I use getText() with array. eg. for(int i=0;i<30
How to retrieve record from table
How to retrieve record from table  Hi. I have a field in database...,kanchipuram for a single record. I have to retrieve these data from the field table.... how to do
Reading text from image file - Java Beginners
Reading text from image file  How Read text from image file

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.