java - JSP - Can't upload image to Google Appengine -
java - JSP - Can't upload image to Google Appengine -
i want upload image appengine therefor have entite myimage(from sourse in internet):
@entity public class myimage implements serializable { /** * */ private static final long serialversionuid = 1l; @id private long id; static int id=1; private string name; blob image; public myimage() { id=(long) id++; } public myimage(string name, blob image) { this.name = name; this.image = image; id=(long) id++; } // jpa getters , setters , empty contructor // ... public blob getimage() { homecoming image; } public void setimage(blob image) { this.image = image; } }
i have code(also internt): (it's servlet used jsp page.)
public class uploadimg extends httpservlet { /** * */ private static final long serialversionuid = 1l; public void dopost(httpservletrequest req, httpservletresponse res) { // image representation seek { helpdebug.msg="start of servlet"; servletfileupload upload = new servletfileupload(); fileitemiterator iter = upload.getitemiterator(req); fileitemstream imageitem = iter.next(); inputstream imgstream = imageitem.openstream(); helpdebug.msg="after open stream"; // build our entity objects blob imageblob = new blob(ioutils.tobytearray(imgstream)); myimage myimage = new myimage(imageitem.getname(), imageblob); helpdebug.msg="after creating image"; // persist image backendfactory.getinstance().sendimg(myimage); helpdebug.msg="after instance "; // respond query res.setcontenttype("text/plain"); res.getoutputstream().write("ok!".getbytes()); } grab (exception ex) { seek { res.getoutputstream().write(ex.getmessage().getbytes()); } grab (ioexception e) { // todo auto-generated grab block e.printstacktrace(); } } } }
when check datasource viewer can see object type myimage created not right content. (the name field there null)
i think have problem getting info jsp file follows:
<%@page import="com.example.servlets.helpdebug"%> <%@ page language="java" contenttype="text/html; charset=windows-1255" pageencoding="windows-1255"%> <!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=windows-1255"> <title>insert title here</title> </head> <body> <form action="uploadimg" method="post" enctype="multipart/form-data"> <input name="name" type="text" value=""> <br /> <input name="imagefield" type="file" size="30"> <br /> <input name="submit" type="submit" value="sumbit"> <% helpdebug.desc = request.getparameter("name") == null ? "null :p" : request.getparameter("name"); out.println(helpdebug.getmsg()); %> </form> </body> </html>
the servlet declartion:
<servlet> <servlet-name>uploadimg</servlet-name> <servlet-class>com.example.servlets.uploadimg</servlet-class> </servlet> <servlet-mapping> <servlet-name>uploadimg</servlet-name> <url-pattern>/uploadimg</url-pattern> </servlet-mapping>
any ideas??
follow examples on blobstore java api overview upload images. it's much easier trying in code.
java jsp google-app-engine servlets
Comments
Post a Comment