[英]How can I use Java variable in HTML tag in JSP?
I'm trying the following code in my .jsp file:我正在我的 .jsp 文件中尝试以下代码:
<select>
<%DBHandler db= new DBHandler();%>
<%db.init();%>
<%String[] res= db.getExpertise();%>
<% for(int i=0;i< res.length;i++){ %>
<option value="<%=res[i]%>"><%=res[i]%></option>
<%}%>
</select>
But, I don't know how to assign value in a tag using a variable in java code.但是,我不知道如何使用 Java 代码中的变量在标签中赋值。
Hope this will help your problem;希望这能帮助您解决问题;
1. Directives 1. 指令
<%@page language="java" %>
2. Declarations 2. 声明
<%!
int radius = 7;
double pi = 3.1415;
%>
3. Scriptlets 3. 小脚本
<%
String id, name, dob, email, address;
id = request.getParameter("id");
name = request.getParameter("name");
dob = request.getParameter("dob");
email = request.getParameter("email");
address = request.getParameter("address");
sessionEJB.addClient(id, name, dob, email, address);
%>
4. Expressions 4. 表达式
<%!
double radius = 7;
double pi = 22/7;
double area()
{
return pi*radius*radius;
}
%>
<html>
<body>
Area of circle is <%= area() %>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.