简体   繁体   English

将参数从会话传递到 JSP 文件中的 javascript

[英]Passing arguments from session to javascript in a JSP file

I am creating a web app and I am using LDAP for authentication.我正在创建一个 Web 应用程序并且我正在使用 LDAP 进行身份验证。 In the login page I get a "Name" and "Phone number" from Active directory and I store these two variables in the session.在登录页面中,我从 Active Directory 获得了“姓名”和“电话号码”,并将这两个变量存储在会话中。 Then it goes to the main page where I grab the values from the session:然后它转到我从会话中获取值的主页:

<%
  Object name = session.getAttribute("name");
  Object ext = session.getAttribute("ext");
%>

I am also using DWR to be able to use the classes I have in the backend such as a class for database operations called DBOps.我还使用 DWR 来使用后端中的类,例如称为 DBOps 的数据库操作类。 Inside DBOps there is a method that will update a phone number.在 DBOps 中,有一种方法可以更新电话号码。

And then in the JSP file I have a javascript to handle that and it works perfectly fine, except Id'like to pass an argument to the function such as the phone number to update.然后在 JSP 文件中,我有一个 javascript 来处理它,它工作得非常好,除了我想将一个参数传递给函数,例如要更新的电话号码。

This all happens when the user clicks on teh button so I have:当用户点击按钮时,这一切都会发生,所以我有:

<button onclick="updateDN();">Update</button>

My question is how can I pass "ext" to updateDN so it would be我的问题是如何将“ext”传递给 updateDN 所以它会是

<button onclick="updateDN(ext);">Update</button>

There are many threads that address this problem but I was not able to get any of the solutions to work in my situation.有很多线程可以解决这个问题,但我无法获得任何解决方案来解决我的情况。 I hope somebody can help.我希望有人可以提供帮助。

Thanks!谢谢!

You can simply pass the object as a parameter by using the JSP Expression tag您可以使用JSP 表达式标记简单地将对象作为参数传递

<button onclick="updateDN(<%=ext%>);">Update</button>

Or bypassing the parameter directly from the session object.或者直接从会话对象绕过参数。

<button onclick="updateDN(<%=session.getAttribute("ext")%>);">Update</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM