gpt4 book ai didi

java - 显示 http header servlet 不显示任何内容

转载 作者:行者123 更新时间:2023-11-30 08:59:33 25 4
gpt4 key购买 nike

这是我显示请求(client) header 的起始 servlet 之一:

public class ShowHeaders extends HttpServlet {

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title Request's HTTP Headers </title>");
out.println("</head>");
out.println("<body>");
out.println("<P> HTTP Headers Sent by your client: </p>");

Enumeration enumeration = request.getHeaderNames();
while (enumeration.hasMoreElements()) {
String headerName = (String) enumeration.nextElement();
String headerValue = request.getHeader(headerName);
out.println("<b>" + headerName + " </b> ");
out.println(headerValue + "<br>");
}
out.println("</body>");
out.println("</html>");
}
}

我的 web.xml 文件:

...
<servlet>
<servlet-name>ShowHeaders</servlet-name>
<servlet-class>com.jspbook.ShowHeaders</servlet-class>

</servlet>


<servlet-mapping>
<servlet-name>ShowHeaders</servlet-name>
<url-pattern>/ShowHeaders</url-pattern>
</servlet-mapping>
...

但问题是当我正确部署它并尝试 http://127.0.0.1:8080/jspbook/ShowHeaders 时,只显示一个空白页面!

我的代码有什么问题?

最佳答案

out.println("<title> Request's HTTP Headers </title>"); 

只需关闭您的标题标签

enter image description here

关于java - 显示 http header servlet 不显示任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27193797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com