RobinHo
RobinHo

Reputation: 575

Reload JSTL,EL,Scriptlets without refreshing the page

I have a jsp page(calendar) with lots of JSTL tags in it. I set the attributes in my servlet and get them in my jsp page thanks to JSTL, EL.

When I press nextweek, I open a xmlhttp which sends a GET to my servlet(Ajax). All my attributes renew so i want to get them again in my jsp page. I do not want to dispatch the servlet to my jsp page because of performance latency. I don't want to fetch servlet results because they are attributes.

I just want to refresh my JSTL & EL so they will get the new values (without refreshing the page).

Is this an illogical way of thinking? but anyway, how can I refresh my JSTL,EL, scriptlets so the new values will appear?

Upvotes: 2

Views: 4471

Answers (2)

Luiggi Mendoza
Luiggi Mendoza

Reputation: 85789

I just want to refresh my JSTL & EL so they will get the new values (without refreching the page)

This is impossible. Note that EL and JSTL run on server side in view build time, so once they're applied when generating the server response, they can't be updated in the page until the server generates new content using the view (basically, your JSP with JSTL, EL and other components)1.

You should look into AJAX requests to your servlet (or the controllers you're using) and probably handling a JSON response to resolve the behavior of your JSP page.

More info:

1 Scriptlets also fall in server side category but I omit them since you should not use them for being highly discouraged to use in modern Java web development. More info How to avoid Java code in JSP files?

Upvotes: 4

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 280141

HttpServlets, JSP, JSTL, EL, and scriptlets are all server side components, ie. get executed on the server to produce an HTTP response. Javascript and AJAX are client side components, ie. work on the returned HTTP response.

You cannot refresh my JSTL & EL on the client side because they simply do not exist.

A possible (and common) solution is to have the request you make with AJAX produce a JSON response which you use to populate/replace HTML elements, where your EL had previously been used to set a value.

Upvotes: 1

Related Questions