Is it possible to use the value of the jsp variable to initialize the JQUERY variable?

I have the following questions:

  • How can I use a JSP variable / array in JQUERY code? Here, the JQUERY code is always stored in a separate .js file, and this file is included in the JSP file.

  • Actually I want to initialize a JQUERY array of a JSP variable. So please help me complete this task.

+5
source share
4 answers

In a plain old JSP

<script>
  var someText = "<%= myBean.getText() %>";
</script>

Using EL (Expression Language)

<script>
  var someText = "${myBean.text}";
</script>

Using Struts

<script>
  var someText = '<bean:write name="myBean" property="text" />';
</script>

Using JSTL

<script>
  var someText = '<c:out value="${myBean.text}" />';
</script>

, Javascript JSP. , HTML/XHTML, JS .

+17

Java/JSP - HTML/CSS/JS. HTML/CSS/JS . HTML/CSS/JS webbrowser . Rightclick Java/JSP.

JSP - , HTML/CSS/JS Java taglibs/EL .

, , JavaScript Java/JSP, , , Java , JavaScript.

<script>var foo = '${bean.foo}';</script>

. , JavaScript, JSP/EL. , ${bean.foo} bar, HTML/CSS/JS, , :

<script>var foo = 'bar';</script>

, , Java/JSP JavaScript, , , - JavaScript (HTTP) HTTP-. .

+1

. -.

<script>
   var fromJsp = '${theVar}';
</script>

, . , JSON .

, . JSP- JavaScript ( JavaScript JSP-).

0

-

<input type="hidden" id="var1" value="<%=jspVar%>" />

var1 jQuery.

0

All Articles