using bean:???? (write?) to display text in a JSP

I'm new to this so bear with me...  I have a JSP file that displays text from a class in a standard JSP way ie;
<%NominalSummaryForm bean = (NominalSummaryForm) session.getAttribute("NominalSummaryForm");%>
with the following for extracting values:
<%=bean.getScreenTitle()%>

How can I use something like <bean:?something?> to display the data instead?  

All the tutorials I've managed to find don't seem to make it simple enough (for me anyway :)

Thanks, Simon
ssherlockAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

paskalCommented:
See this example:

<jsp:useBean id="loginUser" scope="session" class="com.unilever.supplychain.model.admin.User"/>
<jsp:setProperty name="loginUser" property="name" value="paskal" />
<html>
<head>
<title>Some title</title>

</head>
<body >

<jsp:getProperty name="loginUser" property="name" />
</body>
</html>


This should get you at the right track.
0
cheekycjCommented:
in your case it should be just this:

<jsp:useBean id="NominalSummaryForm" scope="session" class="com.yourcompany.NominalSummaryForm"/>

<jsp:getProperty name="NominalSummaryForm" property="screenTitle" />

though I would recommend changing your attribute name that you set from "NominalSummaryForm" to something that isn't identical to the class name.. something like
"summaryForm" or "sessionSummaryForm"

CJ
0
ssherlockAuthor Commented:
Thanks both, but any ideas how to do it in a more struts-like way?
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

ssherlockAuthor Commented:
Thanks both, but any ideas how to do it in a more struts-like way?
0
cheekycjCommented:
0
cheekycjCommented:
You still have to  use <jsp:useBean> to introduce a reference to an existing bean

to write out a property:

<bean:write name="NominalSummaryForm" property="screenTitle"/>

CJ
0
cheekycjCommented:
you may have to copy the bean over using:
<bean:define id="strutsSummaryForm" name="NominalSummaryForm" class="com.yourcompany.NominalSummaryForm"/>

<bean:write name="strutsSummaryForm" property="screenTitle"/>

CJ
0
kennethxuCommented:
CJ's suggest on <jsp:XXX> tag should works fine for you. but if you'd like to use struts, that's should get you on your way:

<jsp:useBean id="formBean" scope="session" class="com.yourcompany.NominalSummaryForm"/>

<bean:write name="formBean" property="screenTitle"/>

0
ssherlockAuthor Commented:
Thanks all, but now I can't seem to get the data out of the session (I told you I was new to this!).  How do I make use of something like:
=(NominalSummaryForm) session.getAttribute("NominalSummaryForm") ?
0
cheekycjCommented:
This didn't work:
<jsp:useBean id="NominalSummaryForm" scope="session" class="com.yourcompany.NominalSummaryForm"/>


otherwise try this:
<%
  NominalSummaryForm summaryForm = (NominalSummaryForm) session.getAttribute("NominalSummaryForm");
%>

then use

<bean:write name="summaryForm" property="screenTitle"/>

CJ
0
ssherlockAuthor Commented:
<jsp:useBean id="NominalSummaryForm" scope="session" class="com.yourcompany.NominalSummaryForm"/> doesn't return any data but at least runs.

<%
 NominalSummaryForm summaryForm = (NominalSummaryForm) session.getAttribute("NominalSummaryForm");
%>
and
<bean:write name="summaryForm" property="screenTitle"/>
gives a JSPException because it "can't find bean bean in any scope"
0
ssherlockAuthor Commented:
<jsp:useBean id="NominalSummaryForm" scope="session" class="com.yourcompany.NominalSummaryForm"/> doesn't return any data but at least runs.

<%
 NominalSummaryForm summaryForm = (NominalSummaryForm) session.getAttribute("NominalSummaryForm");
%>
and
<bean:write name="summaryForm" property="screenTitle"/>
gives a JSPException because it "can't find bean bean in any scope"
0
ssherlockAuthor Commented:
<jsp:useBean id="NominalSummaryForm" scope="session" class="com.yourcompany.NominalSummaryForm"/> doesn't return any data but at least runs.

<%
 NominalSummaryForm summaryForm = (NominalSummaryForm) session.getAttribute("NominalSummaryForm");
%>
and
<bean:write name="summaryForm" property="screenTitle"/>
gives a JSPException because it "can't find bean bean in any scope"
0
ssherlockAuthor Commented:
<jsp:useBean id="NominalSummaryForm" scope="session" class="com.yourcompany.NominalSummaryForm"/> doesn't return any data but at least runs.

<%
 NominalSummaryForm summaryForm = (NominalSummaryForm) session.getAttribute("NominalSummaryForm");
%>
and
<bean:write name="summaryForm" property="screenTitle"/>
gives a JSPException because it "can't find bean bean in any scope"
0
cheekycjCommented:
try this:
<%
NominalSummaryForm summaryForm = (NominalSummaryForm) session.getAttribute("NominalSummaryForm");
%>

<bean:define id="strutsSummaryForm" name="summaryForm" class="com.yourcompany.NominalSummaryForm"/>

<bean:write name="strutsSummaryForm" property="screenTitle"/>

But is there a reason why you don't want to use getProperty and want to use Struts for writing.

CJ
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ssherlockAuthor Commented:
Thanks, bean:define did the trick though the actual syntax was:
<bean:define id="Test" name="NominalSummaryForm" scope="session" toScope="page" type="com.pnc.visor.form.NominalSummaryForm" />

The only reason for not using getProperty is because we want to use the Struts way (and it's less typing :)

Thanks for your help.
0
cheekycjCommented:
glad u figured it out.  Thanx for the "A"

CJ
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.