• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Insert text into JSP output with java bean

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi and howdy!

I have a problem in output handling with JSPs.

I want to have an output like:
Text 1
Text 2
Text 3
Text 4

Whereas "Text 1" and "4" come from the JSPand "Text 2" and "3" from a bean.

myText.jsp:myBean.java:The problem is, I get:
Text 2
Text 3
Text 1
Text 4

So the text is always added at the start of the JSP HTML-Code and not within, from where the method is called.

How can I solve this problem?

Is there a more elegant way to solve the problem?

Thanks!
 
Sheriff
Posts: 67637
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Firstly, your JSP is using a lot of old technology. Scriptlets have been discredited for over 8 years now. You should update your JSP knowledge to embrace the JSTL and EL instead.

That said, the problem is that you are trying to emit output via scriptlets rather than scriptlet expressions. If you are going to continue to use scriptlet technology (not recommended), use scriptlet expressions (&using lt;%= %>) rather than scriptlets.
 
Johannes Salter
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is, I have a lot of code in my real bean. I don't want to integrate all this Code into my JSP.

I just need to output one or two lines of HTML-code from my bean at the right position.

Expression like <%= don't work here, since I have a variable number of output elements.
 
Bear Bibeault
Sheriff
Posts: 67637
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your method can return anything. The number of elements doesn't matter. It's all just text.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Johannes Salter wrote:The problem is, I have a lot of code in my real bean. I don't want to integrate all this Code into my JSP.


And you don't need to; sounds like it should be a custom tag instead.
 
Johannes Salter
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Your method can return anything. The number of elements doesn't matter. It's all just text.


Can I return a list of Strings as text?

PS: First, I want to learn basic JSP and servlet handling. Then I continue with custom tags...
 
Bear Bibeault
Sheriff
Posts: 67637
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are just learning, and not supporting a legacy application, why are you using scriptlets rather than doing things the proper way?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Johannes Salter wrote:Can I return a list of Strings as text?


Sure, why not?
 
Run away! Run away! Here, take this tiny ad with you:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic