动态生成html当中的组件
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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义