简体   繁体   English

如何使用Servlet更改JSP上的标签值

[英]How to change tag values on jsp using servlet

Hello I have a jsp with content like 您好,我有一个类似的内容的jsp

<div id="somediv">Sample text</div>
<img id = "mainPicture" src = "file.jpg" height="1024" width="600"/>

and so on. 等等。 Also I have a servlet, that has to handle requests and proceed response, that change jsp content (for example src in mainPicture and text in somediv). 我还有一个servlet,它必须处理请求并进行响应,以更改jsp内容(例如mainPicture中的src和somediv中的text)。

How can I do that? 我怎样才能做到这一点? Can I return some hashmap from servlet and handle it in javascript? 我可以从servlet返回一些哈希图并在javascript中处理它吗?

Well, I used jQuery and called there my servlet. 好吧,我使用了jQuery,并在那里调用了我的servlet。 Then I edited elements attributes with output data in that jQuery function. 然后,我在该jQuery函数中使用输出数据编辑了元素属性。

just insert java code in jsp? 只是在jsp中插入Java代码?

like 喜欢

"<% java-code %>" “ <%Java代码%>”

for direct output use "<%= java-code %>" 对于直接输出,请使用“ <%= java-code%>”

in your example: 在您的示例中:

<% String sample = "Sample teyt";
   String fileSrc = "file.jpg"; %>
<div id="somediv"><%= sample %></div>
<img id = "mainPicture" src = "<%= fileSrc %>" height="1024" width="600"/>

now you just need to edit the Strings in Java when you want to edit the content there 现在,您只需要在Java中编辑字符串时就可以在其中编辑内容

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

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