java - How to store images to jackrabbit and deliver those images to HTML pages? -
java - How to store images to jackrabbit and deliver those images to HTML pages? -
how store images jackrabbit , deliver images html pages? ex. if user upload multiple images 1 html page should able see images in next html page or other page when required
this way:
public class jackrabbitserviceimpl { repository repository = new transientrepository(); public jackrabbitserviceimpl() throws exception{ session session = repository.login( new simplecredentials("username", "password".tochararray())); try{ inputstream stream = new bufferedinputstream(jackrabbitserviceimpl.class.getresourceasstream("red_rose.jpg")); node folder = session.getrootnode(); node file = folder.addnode("redrose.jpg","nt:file"); node content = file.addnode("jcr:content","nt:resource"); binary binary = session.getvaluefactory().createbinary(stream); content.setproperty("jcr:data",binary); content.setproperty("jcr:mimetype","image/gif"); session.save(); }finally{ session.logout(); } } public byte[] getcontentrose() throws exception{ session session = repository.login( new simplecredentials("username", "password".tochararray())); node folder = session.getrootnode(); node file=folder.getnode("redrose.jpg"); node content=file.getnode("jcr:content"); string path = content.getpath(); binary bin = session.getnode(path).getproperty("jcr:data").getbinary(); inputstream stream = bin.getstream(); homecoming ioutils.tobytearray(stream); } }
the servlet
public class testjackrabbitcdn extends httpservlet { /** * */ private static final long serialversionuid = 4158924623219324725l; jackrabbitserviceimpl service=null; @override public void init(){ seek { service=new jackrabbitserviceimpl(); } grab (exception e) { // todo auto-generated grab block e.printstacktrace(); } } public void doget(httpservletrequest request, httpservletresponse response) throws ioexception, servletexception { response.setcontenttype("image/gif"); seek { response.getoutputstream().write(service.getcontentrose()); } grab (exception e) { // todo auto-generated grab block e.printstacktrace(); } response.getoutputstream().flush(); } }
java jackrabbit jcr
Comments
Post a Comment