aspose file tools*
The moose likes JSP and the fly likes Dynamic images in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Dynamic images in jsp" Watch "Dynamic images in jsp" New topic
Author

Dynamic images in jsp

jagmeet singh
Greenhorn

Joined: Jun 25, 2010
Posts: 6
Hello
I want to dynamically out image. The page queries the database. Code is here


Error: the pictures are not added when the page returns "User Deleted"
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.

Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
jagmeet singh
Greenhorn

Joined: Jun 25, 2010
Posts: 6
Hi Bear Bibeault
I have edited my topic. Thanks for guidance!


Bear Bibeault wrote:Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.

Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

But you didn't add the code tags. That will preserve the formatting.

Also, why are you still using scriptlets in JSPs? They have been discredited for over 8 years now. You should really be using JSTL and EL by now. And that would make all of this much much easier.
jagmeet singh
Greenhorn

Joined: Jun 25, 2010
Posts: 6
Actually this was a ready made project i am editing. I was persuing OCP training. And in india , thouse scriplets are still being taught.
I have no choice.
I didnt visited the use tag form. now i have. next time i will use these tags.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

Understood. As long as your are aware that this is old technology that should not be used in new code...

Please add code tags as suggested. It will make the code more readable. Also, what is the specific error message that you are getting? Please include it in code tags as well to preserve the formatting.
jagmeet singh
Greenhorn

Joined: Jun 25, 2010
Posts: 6
edited the code with error.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Look where the quotes are on the fail image tag.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18125
    
    8

This may also not be relevant, but using a query which is built from a string is liable to have problems. If the user's name contained an apostrophe (which some people's names do) then the SQL query will be malformed and an exception will be thrown. Building a query that way also exposes your system to SQL injection attacks. A better-designed system wouldn't do that; it would use PreparedStatement objects for queries with parameters.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

See also: Little Bobby Tables.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18125
    
    8

David Newton wrote:Look where the quotes are on the fail image tag.


It took me a long time to see that, even when it was pointed out. The quotes are in the wrong place in the success image tag too. That's what you get when you have JSP scriptlets generating HTML; too much quote-escaping, hard to read.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

David Newton wrote:Look where the quotes are on the fail image tag.

Building up HTML inside a Java string, inside a JSP, is pretty much a FAIL in and of itself. The whole purpose of a JSP is so that HTML markup can be entered directly as template text.

You might want to refactor to remove the HTML from strings where silly syntax errors are hard to avoid.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Bear Bibeault wrote:FAIL
jagmeet singh
Greenhorn

Joined: Jun 25, 2010
Posts: 6
I got it:
1. The code is buggy, prone to sql injections.
2. It's using old tech

But i have no choice guys. Need to submit the project. I will give live demo and through it away.
the code did not worked :banghead: :--

David Newton wrote:
Bear Bibeault wrote:FAIL

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Really? You tried my code?!

In any case: FIX THE QUOTES.
jagmeet singh
Greenhorn

Joined: Jun 25, 2010
Posts: 6

Earlier net beans was not even allowing me to write the same code. Now its working.
Thanks DAVID NEWTON.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18125
    
    8

jagmeet singh wrote:Earlier net beans was not even allowing me to write the same code. Now its working.
Thanks DAVID NEWTON.


But now we can add "Generates malformed HTML" to its list of sins. (Although probably it was already doing that too, right?)

To put the attribute value quotes in the right place:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamic images in jsp
 
Similar Threads
Problem in displaying result set value
Problem with the "where" query.
alert in servlet with 'Are you sure you want to delete?'
servlet is not working properly
Replacing html tags in servlet code with a html file name ??