Javascript code to read java variable value

  • I have a session variable in a java file. (TestConnection.java)

session.setAttribute ("CONNECTION_DBNAME", dbName);

  • How to read the value of CONNECTION_DBNAME in a javascript file. (utility.js)
+5
source share
5 answers
 First access the variable in scriptlet.

 <% 
    String param= (String)session.getAttribute("CONNECTION_DBNAME");
 %>

Then use like this.

  <script>
  var X = '<%=param%>';
  </script>

then you can access the name with x.

+7
source
    <script>
<%
    String dbname=(String)session.getAttribute("CONNECTION_DBNAME");
%>  
  </script>

this code is useful to you.

+3
source

JSP, , : - <textarea id="txtData" style.display='none'><%=session.getAttribute("CONNECTION_DBNAME") %></textarea>

javascript var dbConnName=document.getElementById("txtData").value;

.

+1

OUTLAWED !

... jsp, div:

<div id="javaValues" style="display: none;">
    <div id="employee">${employee}</div>
    <div id="dept">${dept}</div>
</div>

<div>, <input type="hidden">, -.

javascript ( jQuery) , :

    var employee = $("#employee").html().trim();
    var dept = $("#dept").html().trim();
+1

. Ajax , script.

JSF:

<script>var dbName = "#{myBean.value}";</script>

( - , , ):

<script>var dbName = "#{session.getAttribute('CONNECTION_DBNAME')}";</script>

, , JavaScript . , , -, , . / .

Now, if this is the admin console, you probably still don't want this in JavaScript, but displaying the settings is acceptable. Regardless, you probably don't need them in the session if the connection data is not specific users.

0
source

All Articles