Author | Message |
---|---|
talisunep
Posts: 140
|
Posted 17:59 May 20, 2013 |
professor what kind of changes do we need to make to the class design to add the profile pictures? |
cysun
Posts: 2935
|
Posted 18:13 May 20, 2013 |
1. You need to figure out that. This is a homework after all. 2. Yes. |
talisunep
Posts: 140
|
Posted 13:24 May 21, 2013 |
professor i am getting this error
HTTP Status 500 - Request processing failed; nested exception is java.lang.ClassCastException: org.springframework.web.multipart.commons.CommonsMultipartFile cannot be cast to java.io.File
byte[] image = new byte[(int) ((File) file).length()]; try { FileInputStream fileInputStream = new FileInputStream(file.getName()); fileInputStream.read(image); fileInputStream.close(); } catch (Exception e) { e.printStackTrace(); } |
cysun
Posts: 2935
|
Posted 15:10 May 21, 2013 |
Isn't the error message pretty clear? |
talisunep
Posts: 140
|
Posted 20:49 May 22, 2013 |
professor i am using ImageIO, i am able to retrive the image data via controller/userDao then i use the Image io to convert back to image(jpg in this case) my question is can i pass the file to jsp to display as image ? currently it only displays image.jpg and not the image as i did a models.put("outputFile", outputFile); |
talisunep
Posts: 140
|
Posted 20:57 May 22, 2013 |
in this case i did a test on my controller ImageIO.write(convert, "jpg", new File("/Users/talisuneplongkumer/Desktop/demoUpload/1.jpg")); |
cysun
Posts: 2935
|
Posted 21:44 May 22, 2013 |
You can't just "write" an image to a JSP. A JSP is basically an HTML page (with some dynamic content), and the only way to include an image in HTML is to use the <img> tag. The src attribute of <img> should point to some controller that returns the image (like in the file download example). |
talisunep
Posts: 140
|
Posted 22:18 May 22, 2013 |
okay, professor if i use a different say image controller for the image recovery and handling from databse how can i invoke this image controller when i want to display that image for that id in jsp? if i seperate my lawyer controller display how can the jsp for display for lawyer display image of that lawyer fron another controller? when i visit display lawyer - my lawyer controller gets displayed... can we do something no the jsp like <c:when test="${ not empty userChecked}"> Last edited by talisunep at
22:31 May 22, 2013.
|
cysun
Posts: 2935
|
Posted 22:44 May 22, 2013 |
I don't see what the difficulty is. In your JSP you would have something like <img src="getImage?lawyerId=${lawyer.id}" />. Last edited by cysun at
22:45 May 22, 2013.
|
talisunep
Posts: 140
|
Posted 23:00 May 22, 2013 |
<img src="getImage?lawyerId=${lawyer.id}" />. professor i was wondering for getImage will it be a controller or a method inside lawyer controller? |
talisunep
Posts: 140
|
Posted 00:12 May 23, 2013 |
created a controller servlet it working now... thank u |
talisunep
Posts: 140
|
Posted 05:26 May 23, 2013 |
Professor whats the best way to access/point-to files within the spring directory? For the default lawyer image.. i dont know if i am following the right approach but i am putting a default image called as well as
|
cysun
Posts: 2935
|
Posted 08:10 May 23, 2013 |
I'd put /image in WebContent instead of WEB-INF, and use a <c:if> in the JSP to either load the user image through a controller or the default image by direct link (e.g. <img src="image/default.jpg">). It's easier to program and gives better performance because the browser can cache the the image for all the lawyers who didn't upload their own images. In your approach the correct path to getRealPath() is "/WEB-INF/image/default.jpg". getReadPath() converts a path relative to the application context to a path on disk. |