Webwork Interceptor to implement Ajax functions (Buffalo)

Source: Internet
Author: User

Bolg hasn't been here for a long time. If you have time, let's put a recently written webwork interceptor for your reference. If you have a bug or a better implementation method, please email me.

The following is the implementation code of interceptor:

1 package interceptor;
2
3 Import java. Io. ioexception;
4
5 import org. Apache. log4j. Logger;
6
7 Import com. Caucho. burlap. Io. burlapinput;
8 Import com. Caucho. burlap. Io. burlapoutput;
9 Import com. Caucho. burlap. server. burlapskeleton;
10 Import com. opensymphony. webwork. servletactioncontext;
11 import com. opensymphony. xwork. actioninvocation;
12 Import com. opensymphony. xwork. Interceptor. interceptor;
13
14 public class burlapinterceptor implements interceptor {
15 Private Static logger = logger. getlogger (burlapinterceptor. Class );
16 public void destroy (){
17 // todo auto-generated method stub
18
19}
20
21 public void Init (){
22 // todo auto-generated method stub
23
24}
25
26 Public String intercept (actioninvocation Invocation) throws exception {
27 burlapinput in = new burlapinput (servletactioncontext. getrequest ()
28. getinputstream ());
29
30 burlapoutput out = new burlapoutput (servletactioncontext. getresponse (). getoutputstream ()){
31 public void startreply () throws ioexception {
32 print ("<? XML version = \ "1.0 \" encoding = \ "UTF-8 \"?> <Burlap: reply xmlns: burlap = \ "http://www.buffalo.net/burlap/\"> ");
33}
34 };
35
36 burlapskeleton _ skeleton = new burlapskeleton (Invocation. getaction ());
37
38 try {
39 _ skeleton. Invoke (In, out );
40}
41 catch (throwable e ){
42 logger. Error ("cocould not invoke burlap", e );
43}
44 return NULL;
45}
46
47}
48

Then define in xwork. xml: 1 <interceptors>
2 <interceptor name = "burlap" class = "Interceptor. burlapinterceptor"/>
3 </interceptors>
4

It is best to use this Interceptor to define your own bean, for example: 1 <action name = "classtree" class = "classtreeaction" method = "getclasslist">
2 <Interceptor-ref name = "burlap"/>
3 </Action>

On the page, you can use the following JavaScript code to call this action:
VaR BFL = new Buffalo ("classtree. Page ");
BFL. remotecall ("getclasslist", [acadyear, semester], function (reply ){...});

If you don't know buffalo, you can go to his website to see: http://www.amowa.net/buffalo/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.