[英]Use Java variable in HTML tag
I'd like to be able to use a java variable as one of the attributes of my HTML tag.我希望能够使用 java 变量作为我的 HTML 标记的属性之一。 For example, I'd like to be able to do this:例如,我希望能够做到这一点:
<% String questionId = "question" %>
Question: <textarea rows="5" cols="20" name=questionId><%=question %></textarea>
Where the name attribute would equal "question".其中 name 属性等于“问题”。 The above doesnt work;以上不起作用; is there any possible way to do this?有没有办法做到这一点?
You are not using the variable you set.您没有使用您设置的变量。 Means you set questionId
and accessing question
It has to be fixed as below意味着您设置了questionId
并访问了question
它必须如下修复
<% String questionId = "question" %>
Question: <textarea rows="5" cols="20" name=questionId><%=questionId %></textarea> <br>
you've forgot the semicolon.你忘记了分号。 try this it must work :试试这个它必须工作:
<% String questionId = "question"; %>
Question: <textarea rows="5" cols="20" name=questionId><%=question %> </textarea> <br>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.