在上一例helloworld的基礎(chǔ)上開發(fā)帶有jsp和servlet的插件,目錄結(jié)構(gòu)如下:
1.添加Servlet文件HelloWorldServlet.java
01 package org.jivesoftware.openfire.plugin;
02
03
04 import java.io.IOException;
05 import java.io.PrintWriter;
06 import javax.servlet.ServletException;
07 import javax.servlet.http.HttpServlet;
08 import javax.servlet.http.HttpServletRequest;
09 import javax.servlet.http.HttpServletResponse;
10
11 public class HelloWorldServlet extends HttpServlet {
12
13 private static final long serialVersionUID = -6093345417438012819L;
14
15 @Override
16
17 protected void doGet(HttpServletRequest req, HttpServletResponse resp)
18
19 throws ServletException, IOException {
20
21 //
super.doGet(req, resp);
22
23
24 resp.setContentType("text/plain");
25
26 PrintWriter out = resp.getWriter();
27
28 System.out.println("helloworld
servlet doget");
29
30 out.print("helloworld
servlet doget");
31
32 out.flush();
33
34 }
35
36
37 @Override
38
39 protected void doPost(HttpServletRequest req, HttpServletResponse resp)
40
41 throws ServletException, IOException {
42
43 //
super.doPost(req, resp);
44
45
46 resp.setContentType("text/plain");
47
48 PrintWriter out = resp.getWriter();
49
50 System.out.println("helloworld
servlet dopost");
51
52 out.print("helloworld
servlet dopost");
53
54 out.flush();
55
56 }
57
58
59 @Override
60
61 public void destroy() {
62
63 super.destroy();
64
65 }
66
67
68 @Override
69
70 public void init() throws ServletException {
71
72 super.init();
73
74 }
75
76 }
2.配置Servlet,在web/WEB-INF添加web-custom.xml文件
3.添加jsp文件在web目錄下,文件名為helloworld_servlet.jsp
3.重新配置Plugin.xml,,主要增加adminconsole字段。
注意:item節(jié)點(diǎn)下的id屬性值對(duì)應(yīng)jsp中servlet"/>的content值,。
4.重新編譯openfire,,在服務(wù)器設(shè)置中可以看到Servlet插件了。
5.點(diǎn)擊HelloWorldServlet
IE跳轉(zhuǎn)頁(yè)面為
同時(shí)在還看到:
至此,,帶jsp和servlet的插件開發(fā)到此結(jié)束,。
|