4.动态生成html当中的组件
有时html里的字数太多, 而且有一定的规律时,我们就可以用如下的方法产生动态的内容。
例 1.4.1
test.jsp:
<%@ page import="java.util.Date"%>
<%@ page import="java.text.*"%>
<%@ page contentType="text/html; charset=GBK" %>
<jsp:useBean id="se" class="com.GenerateSelect" scope="page"/>
<html>
<body >
<%
int d=Integer.parseInt(new SimpleDateFormat("dd").format(new Date()));
int y=Integer.parseInt(new SimpleDateFormat("yyyy").format(new Date()));
int m=Integer.parseInt(new SimpleDateFormat("MM").format(new Date()));
String str=se.set(y,m,d);
%>
<%=str%>
</body>
</html>
package com;
public class GenerateSelect {
public String set(int y,int m, int d) {
String addr = "<form method=post action=date name=date>";
addr = "<select name='year' size='1' style='font-size: 9pt' > ";
for (int i = y-25; i <= y 25; i ) {
if (y == i) {
addr = "<option value=" i " selected> " i "年 </option > ";
}
else {
addr = "<option value=" i "> " i "年 </option > ";
}
}
更多请看:https://blog.csdn.net/qq_44638460/article/details/104157182