java - Best approach to display multiple images in JSP -


I have a JSP where I want to display the images of the vehicles from the database. My unit class looks like this:

  Public category vehicle equipment serializable {Private stationary last long serialvarsian UID = 1L; @ID @ Generated Values ​​(strategy = generation type AOTO) @column (name = "id_vehicle") private id idahl; Private string model; Private string maker; Private byte [] image; @ Transgen Private String Encoded Image; // Getters and setters}  

One way to display all the images in JSP looks like this:

 < Code> & lt; C: forEach item = "$ {vehicle}" var = "v" & gt; & Lt; Img src = "data: image / jpg; base64, & lt; c: out value = '$ {v.encodedImage}' / / width =" 214 "height =" 138 "/>   

means the byte array is encoded for the string and everything is new list :

  Import java.util.ArrayList; Import java.util.List; Import org.apache.commons.codec.binary.Base64; Import Organization. Source: Import org.springframework Stereotype.Service; Import org.springframework.transaction.annotation.Transactional; Import ba.spiderweb.carshop.dao.VehicleDao; Import ba.spiderweb.carshop.entity.Vehicle; Import ba.spiderweb.carshop.util.PageConverter ; @ Service @ t Conceptual Public Class Vehicle SIPIIPLP Vehicle Service Implementation {@Attowared Private Vehicle VehicleDown; @ Override Public List & Lt; Vehicles & gt; FindAll () {LIST & lt; Vehicles & gt; Final List = New Arreelist & amp; Vehicles & For the vehicle (V: vehicleDown.FundL ()) {v.setEncodedImage (new string (base64.x.getImage ())); FinalList.add (v); } Return final list; }}  

Multiple images displayed in JSP to rebuild string and new list instead of encoding byte head first Is there a better way to do the vehicles? Probably to encode the byte array in JSP?

Create a sub-menu that maps the URL to the file's contents of the image.

html / jsp

  & lt; C: forEach items = "$ {vehicle}" var = "v" & gt; & Lt; Img src = "picture / $ {v.idVehicle}" width = "214" height = "138" /> & Lt; / C: foreach & gt;  

will call for images at the URL images / 112 , / images / 333 where those numbers are the vehicle IDs < / P>

A servlet will use this user to find and provide the image on a database on this database:

  public class vehicle SRHTT HTTPSWorlet {@Override protected void doGet (HttpServletRequest req, HttpServletResponse resp) ServletException throws, IOException {string path = req.getPathInfo (); // which comes after "/" (I have not tested it) strings strVehicleId = path.substring (path.indexOf ('/')); Int vehicle iid = integer PRIIIN (StrawiniID); // Vehicle Finds Vehicle v = Drive.Findbieperie (Vehicle ID); // send the image resp.setContentType ("image / jpg"); BufferedOutputStream Out = New BufferedOutputStream (resp.getOutputStream ()); Out.write (v.getImage ()); Out.close (); } Do not forget about the path " / images / " on your  web.xml  configuration file. 


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -