将变量分配给HTML中的值 [英] Assign variable to the value in HTML

查看:105
本文介绍了将变量分配给HTML中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 字符串注册=10-120; 
< input type =textname =registrationUpdatevalue =Reg#maxlength =50/>< br>

在上面, value =Reg#这是硬编码。
我想将变量分配给该值。即Means value = registration;

更新我!

解决方案

问题不是很清楚。我会假设变量是在servlet中声明的,因为在JSP中使用Java是不好的做法。为了能够在一个Servlet之间共享一个转发给JSP的变量,你需要将这个变量设置为一个request属性:

 字符串注册=10-120; 
request.setAttribute(注册,注册);

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

 < input type =textname =registrationUpdatevalue =$ {registration}maxlength =50 /> 

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


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!

解决方案

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

这篇关于将变量分配给HTML中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆