Solved

how can i get the value in javabean by jstl?

Posted on 2004-07-30
14
587 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
  • 7
  • 6
14 Comments
 
LVL 27

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 27

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 27

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 27

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 27

Accepted Solution

by:
rrz earned 50 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 27

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 27

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
copyEndy  challenge 15 94
eclipse package explorer vs project explorer view 2 128
eclipse formatting 6 87
diffSum example 4 36
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.

776 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