0

I have a JSP page named User_Ref.jsp whcih has a datepicker. When I click on submit on that page, it is redirected to another JSP page named ref_time_current.jsp. In this JSP page I have used a scriptlet to hold the value which was selected by user from the calendar, i.e. datepicker. The scriptlet is

<%
  Ref_log_current obj = new Ref_log_current();
  String str= request.getParameter("datepicker");
 ref.refarray_vac1(str);
%>

Now I want to use this str variable defined in scriptlet in this way in same JSP page

<c:out value="${ref.refarray_vac1(str)}"></c:out>

But When I execute this refarray_vac1(String Date) method which return list is showing an empty list. I think I'm using the str variable in wrong way. Please correct me.

1
  • 2
    Why are you mixing JSTL and Scriptlets? Use either of them precisely the former. (Use of Scriplets is discouraged for over a decade). JSTL variables , on the other hand are attributes of some kind (page context by default). If you want to access Scriplets variables in JSTL, you will need to put them into some attributes with a scope like pageContext.setAttribute("datepicker");, request.setAttribute("datepicker"); (session or servlet context depending upon the need) and access them in JSTL as attributes with the scope which they have been associated with. Commented Feb 10, 2015 at 12:09

2 Answers 2

3

JSTL has only access to scoped variable, not directly to scriplet ones. But you can easily create a page variable that way :

<%
  Ref_log_current obj = new Ref_log_current();
  String str= request.getParameter("datepicker");
  pageContext.setAttribute("str", str); // store str in page scope under name str
%>

You can then safely access ${str} in the JSP file.

Sign up to request clarification or add additional context in comments.

1 Comment

I already did that.I have to pass this str as an argument in a method as mentioned in question.
1

In JSTL is not possible to use scriptlet variable in expression. Also you don't need to use scriptlet.

You need to import the bean class you create in JSP

<%@ page import="com.beans.Ref_log_current" %>

You can access parameters like this

<jsp:useBean id="ref" class="com.beans.Ref_log_current" scope="page"/>
<c:out value="${ref.refarray_vac1(param.datepicker)}"/>

7 Comments

,Actually when I tried to print str value as <c:out value="value from calender is ${str}"></c:out> nothing is being shown .It means values from jsp page is not being passed into this jsp page.
sorry date is printing,but list is being empty.
What has been printed if <c:out value="value from calender is ${param.datepicker}"/>?
it prints the date which I have chosen for eg-value from calender is 10/10/2014 . Actually its showing an error that Conversion failed when converting date and/or time from character string. As the date selected from calender is of date type and I put it into a string variable.This may be a cause for empty string.Please correct me.
in your sql you can use date function to convert a string to date, or you can parse Date and use it in SQL as parameter, but it's off-topic. What ever the choice you use is up to you.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.