本文整理汇总了Java中javax.servlet.http.HttpServletRequest.upgrade方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServletRequest.upgrade方法的具体用法?Java HttpServletRequest.upgrade怎么用?Java HttpServletRequest.upgrade使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.http.HttpServletRequest
的用法示例。
在下文中一共展示了HttpServletRequest.upgrade方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processRequest
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet UpgradeServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet UpgradeServlet at " + request.getContextPath() + "</h1>");
if (request.getHeader("Upgrade").equals("echo")) {
response.setStatus(SC_SWITCHING_PROTOCOLS);
response.setHeader("Connection", "Upgrade");
response.setHeader("Upgrade", "echo");
request.upgrade(SampleProtocolHandler.class);
logger.info("Request upgraded to SampleProtocolHandler");
}
out.println("</body>");
out.println("</html>");
}
}
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:22,代码来源:UpgradeServlet.java