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
Ads