另外,我们还要实现一个页面,提供输入发送消息的表单,提交后交给后台处理,成功发送后跳转到一个成功页面。表单输入页面为index.jsp,如下所示:
- <%@ page language="Java" import="java.util.*" pageEncoding="UTF-8"%>
- <%
- String path = request.getContextPath();
- String basePath = request.getScheme() + "://"
- + request.getServerName() + ":" + request.getServerPort()
- + path + "/";
- %>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <base href="<%=basePath%>">
- <title>My JSP 'index.jsp' starting page</title>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="expires" content="0">
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="This is my page">
- <!--
- <link rel="stylesheet" type="text/css" href="styles.css" mce_href="styles.css">
- -->
- </head>
- <body>
- <div align="center" style="width: 500px; height: 300px; border:2px; borderColor:black">
- <form action="sendMessage.do" method="post">
- <table align="center">
- <tr>
- <th colspan="2">
- 消息发送控制台
- </th>
- </tr>
- <tr>
- <td>
- 消息内容:
- </td>
- <td>
- <input type="text" name="message">
- </td>
- </tr>
- <tr>
- <td align="center" colspan="2">
- <input type="reset" value="清除">
- <input type="submit" value="发送">
- </td>
- </tr>
- </table>
- </form>
- </div>
- </body>
- </html>
成功页面为success.jsp,就是给一个成功的提示信息,如下所示:
- <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
- <%
- String path = request.getContextPath();
- String basePath = request.getScheme() + "://"
- + request.getServerName() + ":" + request.getServerPort()
- + path + "/";
- %>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <base href="<%=basePath%>">
- <title>My JSP 'index.jsp' starting page</title>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="expires" content="0">
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="This is my page">
- <!--
- <link rel="stylesheet" type="text/css" href="styles.css" mce_href="styles.css">
- -->
- </head>
- <body>
- <div align="center" style="width: 500px; height: 300px; border:2px; borderColor:black">
- <form action="sendMessage.do" method="post">
- <table align="center">
- <tr>
- <th colspan="2">
- 消息发送报告
- </th>
- </tr>
- <tr>
- <td colspan="2">
- 状态:发送成功
- </td>
- </tr>
- <tr>
- <td align="center" colspan="2">
- <a href="index.jsp" mce_href="index.jsp">返回</a>
- </td>
- </tr>
- </table>
- </form>
- </div>
- </body>
- </html>
至此,我们可以将实现的简单web工程发布到Tomcat容器,然后启动Tomcat服务器,通过页面可以发送消息,并通过日志查看,实际消息发送和接收的情况。