我一直在使用 Java servlet 并注意到以下代码中的一个特殊问题:
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
response.setContentType("text/html");
String url = "/Display.jsp";
CSVFileOperations csvfo = new CSVFileOperations();
String header = csvfo.getHeaders().remove();
System.out.println(header);
request.setAttribute("header", header);
request.getServletContext().getRequestDispatcher(url).forward(request,
response);
特别是,这一行:
request.setAttribute("header", header);
我将字符串标识符和变量名设置为相同。当我通过 调用我的 .jsp 文件中的这个变量时${header},我得到以下输出:
{accept-language=en-US, ua-cpu=AMD64,
cookie=JSESSIONID=1E0C2784352A46D6EFDE0F8A522F4, host=localhost:8080,
connection=Keep-Alive, cache-control=no-cache, accept-encoding=gzip,
deflate, accept=image/gif, image/jpeg, image/pjpeg, application/x-ms-
application, application/xaml+xml, application/x-ms-xbap, */*, user-
agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64; Trident/7.0; rv:11.0) like
Gecko}
但是,当我将字符串标识符从更改为"header"并"head"在 ${head}.jsp 页面中调用时,我得到了预期的输出。
我的问题是,这是怎么回事?
呼唤远方
相关分类