openfire_插件开发-jsp/servlet

本文详细介绍了如何使用Openfire开发插件,从创建HelloWorld开始,逐步深入到Servlet整合与配置,最终实现了一个完整的插件功能。包括插件XML配置、Java类实现、Servlet开发及部署等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.openfire编译运行正常,helloworld工作。参见:openfire_插件开发-helloworld

2.openfire_src/src/plugins/xhcplugin/src/增加web文件夹,添加xhcplugin-birdnew.jsp文件:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>hello world</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="pageID" content="helloworld-service" />
</head>

<body>
	<h3>
		hello world jsp!! <a href="/plugins/xhcplugin/servlet">HelloWorldServlet</a>
	</h3>
	<div class="jive-contentBoxHeader">jive-contentBoxHeader</div>
	<div class="jive-contentBox">jive-contentBox</div>

	<div class="jive-table">
		<table border="1">
			<thead>
				<tr>
					<th>name</th>
					<th>machine ID</th>
					<th>public key</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td align="center">xiao ming</td>
					<td align="center">qq123456</td>
					<td align="center">123333</td>
				</tr>
				<tr class="jive-even">
					<td align="center">xiao hong</td>
					<td align="center">qq11111</td>
					<td align="center">222229</td>
				</tr>
				<tr class="jive-odd">
					<td align="center">da wang</td>
					<td align="center">12ww33</td>
					<td align="center">9876500</td>
				</tr>
			</tbody>
		</table>
	</div>
</body>
</html>


 
 

注意:
hello world jsp!! <a href="/plugins/xhcplugin/servlet">HelloWorldServlet</a>
/plugins/xhcplugin/servlet表示家目录下,xhcplugin插件的servlet。这里如果配置错误,servlet无法工作
和下面的web-custom.xml里面的内容应一致

 
 

3.修改plugin.xml

<?xml version="1.0" encoding="UTF-8"?>
<plugin>
    <!-- Main plugin class -->
    <class>com.xhcbird.xhcplugin.HelloWorld</class>

    <!-- Plugin meta-data -->
    <name>xhcplugin</name>
    <description>plugin xhc play.</description>
    <author>xhcbird</author>

    <version>1.0</version>
    <date>03/04/2014</date>
    <url>http://www.igniterealtime.org/projects/openfire/plugins.jsp</url>
    <minServerVersion>3.0.0</minServerVersion>
    <licenseType>gpl</licenseType>

    <!-- Admin console entries -->
    <adminconsole>
        <!-- More on this below -->
        <tab id="mytab" name="xhcbird" description="Click to manage...">
            <sidebar id="mysidebar" name="HelloWorld">
                <item id="helloworld-service" name="maybebest"
                   url="xhcplugin-birdnew.jsp"
                   description="Click to administer settings for my plugin" />
            </sidebar>
        </tab>
    </adminconsole>
</plugin>


4.在HelloWorld.java相同目录下,增加HelloWorldServlet.java文件

package com.xhcbird.xhcplugin;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloWorldServlet extends HttpServlet {

	@Override
	public void init() throws ServletException {
		super.init();
	}

	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		super.doGet(request, response);

		response.setContentType("text/plain");
		PrintWriter out = response.getWriter();
		System.out.println("请求HelloWorldServlet doGet Method");
		out.print("请求HelloWorldServlet doGet Method");
		out.flush();
	}

	@Override
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		super.doPost(request, response);

		response.setContentType("text/plain");
		PrintWriter out = response.getWriter();
		System.out.println("请求HelloWorldServlet doPost Method");
		out.print("请求HelloWorldServlet doPost Method");
		out.flush();
	}

	@Override
	public void destroy() {
		super.destroy();
	}
}


5.在openfire_src/src/plugins/xhcplugin/src/web下,增加WEB-INF文件夹,创建文件web-custom.xml。

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>

	<servlet>
		<servlet-class>com.xhcbird.xhcplugin.HelloWorldServlet</servlet-class>
		<servlet-name>HelloWorldServlet</servlet-name>
	</servlet>

	<servlet-mapping>
		<servlet-name>HelloWorldServlet</servlet-name>
		<url-pattern>/servlet</url-pattern>
	</servlet-mapping>
</web-app>


6.目录结构如图:

7.运行,效果如图:


8.本文参考该博客:跟我一步一步开发自己的Openfire插件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值