如何使用servlet更改jsp上的标记值

时间:2022-10-17 21:19:01

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中的文本)。

How can I do that? Can I return some hashmap from servlet and handle it in javascript?

我怎样才能做到这一点?我可以从servlet返回一些hashmap并在javascript中处理它吗?

2 个解决方案

#1


0  

just insert java code in jsp?

只是在jsp中插入java代码?

like

"<% java-code %>"

“<%java-code%>”

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中的字符串,就可以在其中编辑内容

#2


0  

Well, I used jQuery and called there my servlet. Then I edited elements attributes with output data in that jQuery function.

好吧,我使用了jQuery并在那里调用了我的servlet。然后我用jQuery函数编辑了输出数据的元素属性。

#1


0  

just insert java code in jsp?

只是在jsp中插入java代码?

like

"<% java-code %>"

“<%java-code%>”

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中的字符串,就可以在其中编辑内容

#2


0  

Well, I used jQuery and called there my servlet. Then I edited elements attributes with output data in that jQuery function.

好吧,我使用了jQuery并在那里调用了我的servlet。然后我用jQuery函数编辑了输出数据的元素属性。