?
Solved

I'm having a problem with accessing variables using JSTL ...

Posted on 2008-11-05
5
Medium Priority
?
939 Views
Last Modified: 2013-11-24
First, I started web development only a few months ago.  So, my question may seem generic, but I need help.

I have a filen events.jsp with 2 forms.  The first form is an input form, the second form is a search form which pulls query results into a datagrid (I'm using displaytag for the table).  These records can be edited in the first form.  When I select a record in form 2, in my control.jsp, I pull the record from the DB, and c:redirect to events.jsp using the reults as parameters (in results, .  When I make changes to the record, my control.jsp completes the action and I c:redirect the results and msg to events.jsp from control.jsp.  

Everthing works, except I not able to use ${param.results} to take action.  I've put debug code to display the value and my results shows in events.jsp.  But, my condition (c:if) cannot see the value.  I even tried using a session scope variable declared in control.jsp, but this doesn't seem to work either.  

My c:set statements from control.jsp:
   <c:set var='results' value='Event Add Error!' scope='session' />
   <c:set var='msg' value='${errMsg}' scope='session' />

I tried to access the sessionScope variable in events.jsp by using the following with no luck, results is empty:
   <c:if test="${!empty sessionScope.results}" >
         <script language="JavaScript">
         <!--
                   //Do some things here ...
      if ("${sessionScope.results}" == "Event Add Error!"){
          validateEventForm(document.eventsEditform);
          messageWindow("${sessionScope.results}", "${sessionScope.msg}");
      }
          //-->
         </script>
   </c:if>

I also tried to access the parameter variable in events.jsp by using the same code with simple change as follows with results being empty:
   <c:if test="${!empty param.results}" >
         <script language="JavaScript">
         <!--
                   //Do some things here ...
      if ("${param.results}" == "Event Add Error!"){
          validateEventForm(document.eventsEditform);
          messageWindow("${param.results}", "${sessionScope.msg}");
      }
          //-->
         </script>
   </c:if>


Is there something I'm not understanding about using the c:set?  If I set a session variable in control.jsp, shouldn't I be able to see it in events.jsp?  Why would the param.results and param.msg be empty (but print out in my debug statements?  Do you have any suggestions?

Thanks in advance.

0
Comment
Question by:csaexperts
  • 3
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
darkapple earned 1500 total points
ID: 22893106
i just can't find error for now...

check once if value is set with



in events.jsp or you can either check whether there is session variable present or not with


try once like this


       <!-- Do something here -->      
       
      




Hope this helps
0
 
LVL 9

Assisted Solution

by:darkapple
darkapple earned 1500 total points
ID: 22893163
are you using this tag-library for core.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
0
 

Author Comment

by:csaexperts
ID: 22896135
I already have the <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> .  It's a different order,
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>, would that make a difference??

I also tried the c:out for param.msg, which printed the message (I see the value) and for what ever reason (?) the param annotation now works.  But the sessionScope variable is still not showing.

I'm not sure how to use the suggestion  logic:notPresent ....   Could you elaborate?

</logic:notPresent>

0
 
LVL 9

Assisted Solution

by:darkapple
darkapple earned 1500 total points
ID: 22902650
that doesn't make differnce.



       <!-- Do something here -->      
       
     



Here i'm checking where session variable results is present or not.

The statements inside  comes into action when results variable is absent in session.

and  checks for presence of variable in session.


The equivalent of following code


   


will be like






hope this helps you


0
 

Author Closing Comment

by:csaexperts
ID: 31513715
The logic:present annotation was helpful, although not a complete solution.  I'm able to get around my dilemma by passing parameters from control.jsp to events.jsp.  This seems to be working now.  Thank for you help, I learned something which is always good.  MJ
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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.

839 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