将变量分配给 HTML 中的值

发布于 2024-12-22 23:46:58 字数 240 浏览 2 评论 0原文

String registration="10-120";
<input type="text" name="registrationUpdate" value="Reg#" maxlength="50" /><br>

上面的 value="Reg#" 是硬代码。 我想将变量分配给该值。即均值=注册;

更新我!

String registration="10-120";
<input type="text" name="registrationUpdate" value="Reg#" maxlength="50" /><br>

In the above , value="Reg#" which is hard code.
I want to assign variable to the value. i.e. Means value=registration;

update me!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独木成林 2024-12-29 23:46:58

你的问题不是很清楚。我假设该变量是在 servlet 内部声明的,因为在 JSP 中使用 Java 是不好的做法。为了能够在转发到 JSP 的 Servlet 之间共享变量,您需要将此变量设置为请求属性:

String registration = "10-120";
request.setAttribute("registration", registration);

然后在 JSP 中,您可以使用 JSP EL 获取“注册”属性的值

<input type="text" name="registrationUpdate" value="${registration}" maxlength="50" />

:应该阅读 Java EE 教程:http://docs.oracle.com/javaee/5/tutorial/doc/bnadp.html

Your question is not very clear. I'll assume the variable is declared inside a servlet, because it's bad practice to use Java in a JSP. To be able to share a variable between a Servlet whic forwards to a JSP, you need to set this variable into a request attribute:

String registration = "10-120";
request.setAttribute("registration", registration);

And then in the JSP, you can get the value of the "registration" attribute using the JSP EL:

<input type="text" name="registrationUpdate" value="${registration}" maxlength="50" />

You should read the Java EE tutorial: http://docs.oracle.com/javaee/5/tutorial/doc/bnadp.html

猥︴琐丶欲为 2024-12-29 23:46:58

非常简单

    <% String registration="10-120"; %>
    <input type="text" name="registrationUpdate" value="<%=registration%>" maxlength="50" />

希望这会帮助你

itz very simple

    <% String registration="10-120"; %>
    <input type="text" name="registrationUpdate" value="<%=registration%>" maxlength="50" />

hope this will help you

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文