/*
* Generated by the Jasper component of Apache Tomcat
* Version: Apache Tomcat/7.0.47
* Generated at: 2017-08-17 15:30:21 UTC
* Note: The last modified time of this file was set to
* the last modified time of the source file after
* generation to assist with modification tracking.
*/
package org.apache.jsp;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
public final class index_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent {
private static final javax.servlet.jsp.JspFactory _jspxFactory =
javax.servlet.jsp.JspFactory.getDefaultFactory();
private static java.util.Map<java.lang.String,java.lang.Long> _jspx_dependants;
private javax.el.ExpressionFactory _el_expressionfactory;
private org.apache.tomcat.InstanceManager _jsp_instancemanager;
public java.util.Map<java.lang.String,java.lang.Long> getDependants() {
return _jspx_dependants;
}
public void _jspInit() {
_el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
_jsp_instancemanager = org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(getServletConfig());
}
public void _jspDestroy() {
}
public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)
throws java.io.IOException, javax.servlet.ServletException {
final javax.servlet.jsp.PageContext pageContext;
javax.servlet.http.HttpSession session = null;
final javax.servlet.ServletContext application;
final javax.servlet.ServletConfig config;
javax.servlet.jsp.JspWriter out = null;
final java.lang.Object page = this;
javax.servlet.jsp.JspWriter _jspx_out = null;
javax.servlet.jsp.PageContext _jspx_page_context = null;
try {
response.setContentType("text/html;charset=UTF-8");
pageContext = _jspxFactory.getPageContext(this, request, response,
null, true, 8192, true);
_jspx_page_context = pageContext;
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
_jspx_out = out;
out.write("\r\n");
out.write("<!DOCTYPE html>\r\n");
out.write("<html>\r\n");
out.write("<head>\r\n");
out.write(" <title>Java后端WebSocket的Tomcat实现</title>\r\n");
out.write("</head>\r\n");
out.write("<body>\r\n");
out.write(" Welcome<br/><input id=\"text\" type=\"text\"/>\r\n");
out.write(" <button onclick=\"send()\">发送消息</button>\r\n");
out.write(" <hr/>\r\n");
out.write(" <button onclick=\"closeWebSocket()\">关闭WebSocket连接</button>\r\n");
out.write(" <hr/>\r\n");
out.write(" <div id=\"message\"></div>\r\n");
out.write("</body>\r\n");
out.write("\r\n");
out.write("<script type=\"text/javascript\">\r\n");
out.write(" var websocket = null;\r\n");
out.write(" //判断当前浏览器是否支持WebSocket\r\n");
out.write(" if ('WebSocket' in window) {\r\n");
out.write(" websocket = new WebSocket(\"ws://localhost:8081/client/websocket\");\r\n");
out.write(" }\r\n");
out.write(" else {\r\n");
out.write(" alert('当前浏览器 Not support websocket')\r\n");
out.write(" }\r\n");
out.write("\r\n");
out.write(" //连接发生错误的回调方法\r\n");
out.write(" websocket.onerror = function () {\r\n");
out.write(" setMessageInnerHTML(\"WebSocket连接发生错误\");\r\n");
out.write(" };\r\n");
out.write("\r\n");
out.write(" //连接成功建立的回调方法\r\n");
out.write(" websocket.onopen = function () {\r\n");
out.write(" setMessageInnerHTML(\"WebSocket连接成功\");\r\n");
out.write(" }\r\n");
out.write("\r\n");
out.write(" //接收到消息的回调方法\r\n");
out.write(" websocket.onmessage = function (event) {\r\n");
out.write(" setMessageInnerHTML(event.data);\r\n");
out.write(" }\r\n");
out.write("\r\n");
out.write(" //连接关闭的回调方法\r\n");
out.write(" websocket.onclose = function () {\r\n");
out.write(" setMessageInnerHTML(\"WebSocket连接关闭\");\r\n");
out.write(" }\r\n");
out.write("\r\n");
out.write(" //监听窗口关闭事件,当窗口关闭时,主动去关闭websocket连接,防止连接还没断开就关闭窗口,server端会抛异常。\r\n");
out.write(" window.onbeforeunload = function () {\r\n");
out.write(" closeWebSocket();\r\n");
out.write(" }\r\n");
out.write("\r\n");
out.write(" //将消息显示在网页上\r\n");
out.write(" function setMessageInnerHTML(innerHTML) {\r\n");
out.write(" document.getElementById('message').innerHTML += innerHTML + '<br/>';\r\n");
out.write(" }\r\n");
out.write("\r\n");
out.write(" //关闭WebSocket连接\r\n");
out.write(" function closeWebSocket() {\r\n");
out.write(" websocket.close();\r\n");
out.write(" }\r\n");
out.write("\r\n");
out.write(" //发送消息\r\n");
out.write(" function send() {\r\n");
out.write(" var message = document.getElementById('text').value;\r\n");
out.write(" websocket.send(message);\r\n");
out.write(" }\r\n");
out.write("</script>\r\n");
out.write("</html>");
} catch (java.lang.Throwable t) {
if (!(t instanceof javax.servlet.jsp.SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
try { out.clearBuffer(); } catch (java.io.IOException e) {}
if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
else throw new ServletException(t);
}
} finally {
_jspxFactory.releasePageContext(_jspx_page_context);
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
WebSocket j2ee 实现
共25个文件
xml:16个
java:2个
class:2个
需积分: 9 13 下载量 135 浏览量
2017-08-17
23:47:31
上传
评论
收藏 38KB RAR 举报
温馨提示
java WebSocket在Tomcat容器的实现 http://blog.csdn.net/zsg88/article/details/77345216 源代码下载
资源推荐
资源详情
资源评论
收起资源包目录
jstudio-websocket-j2ee.rar (25个子文件)
jstudio-websocket-j2ee
pom.xml 2KB
target
apache-tomcat-maven-plugin
classes
me
gacl
websocket
WebSocketTest.class 3KB
generated-sources
annotations
tomcat
conf
logging.properties 3KB
web.xml 149KB
tomcat-users.xml 1KB
logs
access_log.2017-08-17 860B
work
Tomcat
localhost
client
org
apache
jsp
index_jsp.class 6KB
index_jsp.java 6KB
webapps
src
test
java
main
webapp
WEB-INF
web.xml 222B
index.jsp 2KB
resources
java
me
gacl
websocket
WebSocketTest.java 3KB
.idea
misc.xml 1KB
vcs.xml 164B
.name 22B
copyright
profiles_settings.xml 76B
modules.xml 284B
encodings.xml 367B
compiler.xml 1KB
workspace.xml 25KB
libraries
Maven__javax_javaee_api_7_0.xml 483B
Maven__com_sun_mail_javax_mail_1_5_0.xml 525B
Maven__javax_activation_activation_1_1.xml 527B
artifacts
jstudio_websocket_j2ee_war.xml 345B
jstudio_websocket_j2ee_war_exploded.xml 743B
jstudio-websocket-j2ee.iml 2KB
共 25 条
- 1
资源评论
猪脚踏浪
- 粉丝: 179
- 资源: 15
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功