jsp 使用request为页面添加静态数据的实例(jsp使用js定义的变量)奔走相告

随心笔谈5个月前更新 admin
224 00
🌐 经济型:买域名、轻量云服务器、用途:游戏 网站等 《腾讯云》特点:特价机便宜 适合初学者用 点我优惠购买
🚀 拓展型:买域名、轻量云服务器、用途:游戏 网站等 《阿里云》特点:中档服务器便宜 域名备案事多 点我优惠购买
🛡️ 稳定型:买域名、轻量云服务器、用途:游戏 网站等 《西部数码》 特点:比上两家略贵但是稳定性超好事也少 点我优惠购买

文章摘要

本文主要介绍了一段Java代码的功能和实现逻辑。代码中定义了两个静态的ArrayList<String>变量`list`和`listdc`,并在静态块中初始化为空列表。随后,通过调用`getData()`方法向这两个列表中添加了五个相同的字符串:"dcrewrwe3eeeeeeeeeeeeeeeee"。代码还定义了一个`getDoB`方法,用于处理HTTP请求和响应,通过设置`HttpServletRequest`的字符编码为UTF-8,并将列表中的数据通过`Forward`方法转发到默认页面`/page/default.jsp`。整体代码的目的是通过简单的数据初始化和页面转发实现某种数据展示功能。


public static ArrayList<String> list;
static{
list=new ArrayList<String>();
listdc.add(“dcrewrwe3eeeeeeeeeeeeeeeee”);
listdc.add(“dcrewrwe3eeeeeeeeeeeeeeeee”);
listdc.add(“dcrewrwe3eeeeeeeeeeeeeeeee”);
listdc.add(“dcrewrwe3eeeeeeeeeeeeeeeee”);
listdc.add(“dcrewrwe3eeeeeeeeeeeeeeeee”);
   public static ArrayList<String> listdc;
static{
listdc=new ArrayList<String>();
listdc.add(“dcrewrwe3eeeeeeeeeeeeeeeee”);
listdc.add(“dcrewrwe3eeeeeeeeeeeeeeeee”);
listdc.add(“dcrewrwe3eeeeeeeeeeeeeeeee”);
listdc.add(“dcrewrwe3eeeeeeeeeeeeeeeee”);
listdc.add(“dcrewrwe3eeeeeeeeeeeeeeeee”);
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding(“UTF-8”);
response.setContentType(“text/html”);
ArrayList<String>list=getData();

request.setAttribute(“new”, list);
request.setAttribute(“dc”, listdc);
request.getRequestDispatcher(“/page/default.jsp”).forward(request, response);
}

© 版权声明

相关文章