手机版
你好,游客 登录 注册
背景:
阅读新闻

Spring+JMS+ActiveMQ+Tomcat实现消息服务

[日期:2011-10-06] 来源:Linux社区  作者:shirdrn [字体: ]

另外,我们还要实现一个页面,提供输入发送消息的表单,提交后交给后台处理,成功发送后跳转到一个成功页面。表单输入页面为index.jsp,如下所示:

  1. <%@ page language="Java" import="java.util.*" pageEncoding="UTF-8"%>  
  2. <%  
  3.     String path = request.getContextPath();  
  4.     String basePath = request.getScheme() + "://"  
  5.             + request.getServerName() + ":" + request.getServerPort()  
  6.             + path + "/";  
  7. %>  
  8.   
  9. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  10. <html>  
  11.     <head>  
  12.         <base href="<%=basePath%>">  
  13.   
  14.         <title>My JSP 'index.jsp' starting page</title>  
  15.         <meta http-equiv="pragma" content="no-cache">  
  16.         <meta http-equiv="cache-control" content="no-cache">  
  17.         <meta http-equiv="expires" content="0">  
  18.         <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
  19.         <meta http-equiv="description" content="This is my page">  
  20.         <!--  
  21.     <link rel="stylesheet" type="text/css" href="styles.css" mce_href="styles.css">  
  22.     -->  
  23.     </head>  
  24.   
  25.     <body>  
  26.         <div align="center" style="width: 500px; height: 300px; border:2px; borderColor:black">  
  27.             <form action="sendMessage.do" method="post">  
  28.                 <table align="center">  
  29.                     <tr>  
  30.                         <th colspan="2">  
  31.                             消息发送控制台  
  32.                         </th>  
  33.                     </tr>  
  34.                     <tr>  
  35.                         <td>  
  36.                             消息内容:  
  37.                         </td>  
  38.                         <td>  
  39.                             <input type="text" name="message">  
  40.                         </td>  
  41.                     </tr>  
  42.                     <tr>  
  43.                         <td align="center" colspan="2">  
  44.                             <input type="reset" value="清除">  
  45.                                   
  46.                             <input type="submit" value="发送">  
  47.                         </td>  
  48.                     </tr>  
  49.                 </table>  
  50.             </form>  
  51.         </div>  
  52.     </body>  
  53. </html>  

成功页面为success.jsp,就是给一个成功的提示信息,如下所示:

  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
  2. <%  
  3.     String path = request.getContextPath();  
  4.     String basePath = request.getScheme() + "://"  
  5.             + request.getServerName() + ":" + request.getServerPort()  
  6.             + path + "/";  
  7. %>  
  8.   
  9. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  10. <html>  
  11.     <head>  
  12.         <base href="<%=basePath%>">  
  13.   
  14.         <title>My JSP 'index.jsp' starting page</title>  
  15.         <meta http-equiv="pragma" content="no-cache">  
  16.         <meta http-equiv="cache-control" content="no-cache">  
  17.         <meta http-equiv="expires" content="0">  
  18.         <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
  19.         <meta http-equiv="description" content="This is my page">  
  20.         <!--  
  21.     <link rel="stylesheet" type="text/css" href="styles.css" mce_href="styles.css">  
  22.     -->  
  23.     </head>  
  24.   
  25.     <body>  
  26.         <div align="center" style="width: 500px; height: 300px; border:2px; borderColor:black">  
  27.             <form action="sendMessage.do" method="post">  
  28.                 <table align="center">  
  29.                     <tr>  
  30.                         <th colspan="2">  
  31.                             消息发送报告  
  32.                         </th>  
  33.                     </tr>  
  34.                     <tr>  
  35.                         <td colspan="2">  
  36.                             状态:发送成功  
  37.                         </td>  
  38.                     </tr>  
  39.                     <tr>  
  40.                         <td align="center" colspan="2">  
  41.                             <a href="index.jsp" mce_href="index.jsp">返回</a>  
  42.                         </td>  
  43.                     </tr>  
  44.                 </table>  
  45.             </form>  
  46.         </div>  
  47.     </body>  
  48. </html>  

至此,我们可以将实现的简单web工程发布到Tomcat容器,然后启动Tomcat服务器,通过页面可以发送消息,并通过日志查看,实际消息发送和接收的情况。 

linux
相关资讯       Tomcat 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款