• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EL displaying as text

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSP to JSP using a bean, and the EL code displays as plain text, rather than the evaluated value. If it evaluated to blank or null I could see it, but am not sure why it spits it out as generic text. Yes, I am new to using EL, so please let me know if I'm missing something obvious.

This stems from trying to use a bean to pass data, so really I just need to verify exactly what setProperty does, and if it does something in test1.jsp or test2.jsp.

test1.jsp

test2.jsp

WorkorderBean.java

Screen result:
idNumber: ${workorder.idNumber}
username: ${workorder.username}

I tried bean scope = request, session, application. I tried sticking the EL inside a <c: out> tag. I tried moving the jsp:setProperty up and down. Nothing worked.
Testing with Java6 in Eclipse 3.5 running Tomcat 6 with Firefox 3.5.
 
Sheriff
Posts: 67746
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
That's usually a sign that you web app is misconfigured.

See the JSP FAQ which covers this extensively. Pay particular attention to how your deployment descriptor is declared.
 
Bear Bibeault
Sheriff
Posts: 67746
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
And, after this is straightened out, if you are submitting from one JSP to another just as a quick test, that's fine. In real code, you should never submit a form to a JSP -- always to a servlet task controller.
 
Keri Mathis
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I'll take a look at the configuration.

Yes, my plan is to do JSP to servlet. I'm back to the question I've seen posted a few times where folks are trying to get the html form to auto-populate the bean, and send that to the servlet. I've got the JSP-servlet communication down fine. But I'm really not understanding how/when the following line gets executed, and if it doesn't really load up a bean with matching param values, what does it do?

<jsp:setProperty name="workorder" property="*" />

So I thought I could easily evaluate the bean using a 2nd JSP page. But that's proving difficult as well. Longer-term, I thought if I need to use the setProperty in the 2nd jsp page, I could auto-populate it then forward it to the servlet. But I'm not sure if that will work.
 
Bear Bibeault
Sheriff
Posts: 67746
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

Keri Mathis wrote:Yes, my plan is to do JSP to servlet.
...
trying to get the html form to auto-populate the bean


These two statements are in direct conflict.

You either post to a servlet, or post to a JSP. If you are doing the former, the <jsp:setProperty> tag is obviously not available. If you are doing the latter just to be lazy and use the <jsp:setProperty> tag, well, ...

If you want something that can do the same job, but run in servlet code, check out the BeanUtils.populate() method of the Jakarta Commons BeanUtils project.

I thought if I need to use the setProperty in the 2nd jsp page, I could auto-populate it then forward it to the servlet. But I'm not sure if that will work.


As I indicated above, that's creating a lot of artificial contortions, extra overhead, and violation of best practices, just to be able to use <jsp:getProperty>. Does that really make sense?
 
Keri Mathis
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agreed it would be messy to use a ghost JSP page, but it would beat 100 servlet request.getParameter() calls. I'm surprised there is not a given, standard way to do this. How many html forms are out there submitting to Java servlets, and there's no standard answer to this problem?

I saw you referenced using a Map wrapper, but was not clear how that worked either. But the BeanUtils.setProperty() may be just the thing if I can pass a new bean and the request.getParameterMap(). Thank you for the feedback and the tip.
 
Bear Bibeault
Sheriff
Posts: 67746
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
The servlet spec is pretty sparse and doesn't specify a whole lot of higher-level functionality. That's where really useful projects
like Jakarta Commons comes in very handy!
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Keri

See the changes i have made in your jsp,s to

test1.jsp







test2.jsp



you can use the same bean let me know if it works for you





 
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have slightly misunderstood the use of


The code :



is converted to this at compile time:


here this line:


finds attribute names from request object and calles appropriate setter method on the work order bean.

You have done everything right except place this code:


Means you have to place this code when you have bean attribute values set in request object. Means this code should run after your form submission on test1.jsp not before form submission. So your test1.jsp would be:


and test2.jsp would be:



Happy coding



 
The human mind is a dangerous plaything. This tiny ad is pretty safe:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic