Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how can i get the value in javabean by jstl?

Posted on 2004-07-30
14
Medium Priority
?
610 Views
Last Modified: 2013-11-24
hi,experts
  now i hava a javabean

<jsp:useBean id="idBean" class="mypage.TTest" />

<%
   idBean=idBean.getBean();
%>

now i want to use jstl to get the idBean's value

<%=idBean.getValue();%>
--->
<c:out value="{idBean.value}"/>  ??? can not get the value,how can i do it !
thanks!
0
Comment
Question by:jbas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
14 Comments
 
LVL 28

Expert Comment

by:rrz
ID: 11684503
Try this  instead

<jsp:useBean id="idBean" class="mypage.TTest" />
<c:set var="idBean" value="<%=idBean%>"/>
<c:out value="{idBean.value}"/>
0
 

Author Comment

by:jbas
ID: 11691135
very thanks to rrz@871311,i use your method and it can work well,this is my code
<c:set var="action" value="${param.action}"/>
<c:set var="id" value="${param.id}"/>
<c:set var="idSickness" value="<%=idSickness%>"/>

<c:if test="${!empty id}">
  <c:set var="idSickness" value="${idSickness.getSicknessById(id)}"/>
  <c:set var="action" value="edit"/>
</c:if>

<c:if test="${empty id}">
  <c:set var="action" value="new"/>
</c:if>

html:
<c:out value="${idSickness.treatmentMemo}"/>

now can i use jstl not <%%> in my code
<c:set var="idSickness" value="<%=idSickness%>"/>
can be changed another jstl with no "<%=idSickness%>"

and jstl hava <jsp:useBean id="" class=/> taglib????????


thanks for you!
0
 
LVL 28

Expert Comment

by:rrz
ID: 11695939
>now can i use jstl not <%%> in my code
I don't think you can avoid using an JSP expression ( <%=  %> ).
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 28

Expert Comment

by:rrz
ID: 11700521
I am sorry but I got off on wrong track
Are you sure this doesn't work ?
<jsp:useBean id="idBean" class="mypage.TTest" />
<c:out value="${idBean.value}"/>
0
 

Author Comment

by:jbas
ID: 11700612
yes,this can not work in this.
0
 
LVL 28

Expert Comment

by:rrz
ID: 11700688
Are you using JSTL 1.1  ?
Is there a method  getValue()  in  TTest   ?
0
 

Author Comment

by:jbas
ID: 11702487
yes i use JSTL 1.1 ,and  there  hava a method  getValue()  in  TTest ,i need to jstl2???

thanks!
0
 

Author Comment

by:jbas
ID: 11702500
where hava jstl2.0???
0
 
LVL 28

Accepted Solution

by:
rrz earned 200 total points
ID: 11704452
>where hava jstl2.0???
No, there is just  JSTL 1.1 for now.
The code works for me. I don't why it is not working for you.
What is the method getValue() suppose to return ? A String ? A int  ?
In your initial post for this question, you forgot  the $ . Did you  add it ?  
Finally, check if your installation is good by testing with this
${"Hello from JSTL"}    
that should  display  as just
Hello from JSTL
0
 

Author Comment

by:jbas
ID: 11712028
hi rrz@871311

thanks for your help again,i am make a mistake,you code can work well not use "<%%>",this is my code:

<%@ page contentType="text/html; charset=gb2312" %>
<% request.setCharacterEncoding("gb2312"); %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@ taglib uri="http://my" prefix="myx"%>

<%@ page import="com.beltino.pub.*"%>
<%@ page import="com.beltino.communitymedical.pub.*"%>
<%@ page import="com.beltino.communitymedical.community.Community"%>
<jsp:useBean id="idCommunity" class="com.beltino.communitymedical.community.Community"/>

<c:set var="id" value="${param.id}"/>
<c:set var="action" value="${param.action}"/>
<c:if test="${empty id}">
   <c:set var="action" value="new"/>
</c:if>
<c:if test="${!empty id}">
   <c:set var="action" value="edit"/>
   <c:set var="idCommunity" value="${idCommunity.getCommunityInformation(id)}"/>
</c:if>

in html::can getvalue like this,

<td>
   <INPUT TYPE="text" NAME="communityMemo" Value="${idCommunity.communityMemo}" Size="50" Maxlength="50">
</td>
it work well!

 Best regard for you!
0
 

Author Comment

by:jbas
ID: 12353358
hi, rrz@871311

sorry for trouble you,now when i deplay this page in tomcat ,it can not work,and the error is:

org.apache.jasper.JasperException: /webapp/community/editCommunity.jsp(24,3) The function getCommunityInformation must be used with a prefix when a default namespace is not specified


this :
<c:set var="idCommunity" value="${idCommunity.getCommunityInformation(id)}"/>
will not support in tomcat ???

help me again,thanks!
0
 
LVL 28

Expert Comment

by:rrz
ID: 12359194
Please change
><c:set var="idCommunity" value="${idCommunity.getCommunityInformation(id)}"/>
to  
<c:set var="idCommunity" value="<%=idCommunity.getCommunityInformation(id)%>"/>
rrz

0
 
LVL 28

Expert Comment

by:rrz
ID: 12361464
Please try the following page in both resin and tomcat. What output do you get ?  Look at translated page (in Tomcat's work folder, I don't know resin) for differences.  


<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
          pageContext.setAttribute("pageVar","page");
%>
<jsp:useBean id="beanVar" class="java.lang.String"/>
<% beanVar = "bean"; %>
<c:set var="beanVar" value="${beanVar}"/>
<c:out value="${beanVar}"/>
<c:out value="${pageVar}"/>
0
 

Expert Comment

by:hgbdelphi
ID: 12364832
hi,rrz@871311
 thanks for your help again,i try this page in tomcat5.0.28 and resin3.0.8,and the page is all show :
 page

in resin and tomcat.

if i do this
><c:set var="idCommunity" value="${idCommunity.getCommunityInformation(id)}"/>
to  
<c:set var="idCommunity" value="<%=idCommunity.getCommunityInformation(id)%>"/>

it can work it,but i will change my all page to tomcat.

thanks!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
A solution for Fortify Path Manipulation.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question