从传递的对象中提取额外的Java属性在html中。

huangapple 未分类评论58阅读模式
英文:

Extract additional Java attributes from a passed object in html

问题

假设我有一个用户表,其中具有属性“login”和“password”。我从我的数据库中选择它们:

Query query = entityManager.createQuery("SELECT u FROM User u");

List<User> resultList = query.getResultList();

然后我将列表传递给jsp视图,并对其进行迭代,打印用户登录名:

<s:property value=user.login/>

在客户端是否有可能查看用户的密码,考虑到它们(我假设)存在于页面的源代码中?如果可能的话,该如何实现?

或者在解释的HTML中,未使用的对象属性是否无法访问?

英文:

Suppose I have a table of users that have the attributes "login" and "password". I select them from my DB:

Query query = entityManager.createQuery(&quot;SELECT u FROM User u&quot;);

List&lt;User&gt; resultList = query.getResultList();

Then I pass the list into a jsp view and iterate over it, printing user logins:

&lt;s:property value=user.login/&gt;

Is it possible on the client's side to also view the users' passwords, considering they do (I assume) exist in the page's source code? If it is, how is it done?

Or are unused object attributes inaccessble in interpreted HTML?

答案1

得分: 0

是的,这是可能的,您已经有一个名为 User 的类,它具有属性 loginpassword,因此您可以提取登录名和密码,并将它们注入对象中。

Query query = entityManager.createQuery("SELECT login, password FROM User");
// ...
// 对于表中的每一行
User u = new User(login, password); // 从查询中提取
user_list.add(u); // 将其添加到发送到 JSP 的列表中

然后,当您将列表传递到 JSP 时,您可以使用 getter 方法提取它们:

<s:property value="user.login"/>
<s:property value="user.password"/>
英文:

Yes that's possible , you already have a class User which has the attributes login and password , so you can extract the login and password and inject them into objects

Query query = entityManager.createQuery(&quot;SELECT login,passowrd FROM User&quot;);
...
// for each line on table
User u = new User(login,password); // extracted from the query
user_list.add(u); // add it to the list you&#39;ll send to jsp

Then when you pass the list into JSP , you can extract them with getters :

&lt;s:property value=user.login/&gt;
&lt;s:property value=user.password/&gt;

huangapple
  • 本文由 发表于 2020年6月5日 23:24:15
  • 转载请务必保留本文链接:https://java.coder-hub.com/62218819.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定