在接收参数的OSGi中注册servlet [英] registering servlet in OSGi that receives parameters

查看:123
本文介绍了在接收参数的OSGi中注册servlet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试注册一个将接收参数的HttpServlet(实际上并不关心它是通过POST还是GET进行的,尽管显然首选POST).几乎只是扩展了这里描述的内容:

I'm trying to register a HttpServlet that will receive parameters (don't really care if it is via POST or GET, altough POST preferred obviously). Pretty much just extending what is depicted here:

http://www. javaworld.com/javaworld/jw-06-2008/jw-06-osgi3.html?page=3

在这里:

http://www.peterfriese.de/osgi-servlets-a -happy-marriage/

我不使用声明式注册,首先要看它能正常工作,然后再做其他事情.

I'm not using still declarative registration, first want to see it working, then I'll do the other stuff.

调用时出现疑问:

httpService.registerServlet("/helloworld", new RestServlet(), null, null);

不确定如何告诉HttpService服务器将接受参数.此外,是否必须在每次注册servlet时都使用new()创建HttpServlet,还是可以为不同的别名重用HttpServlet?我问是因为也许可以在alias参数中使用一些通配符,然后让HttpServlet对象处理HttpRequest中出现的任何事情...?

Not sure how to tell HttpService that the server will accept params. Besides, is it mandatory to create a HttpServlet with new() everytime a servlet is registered or can I reuse the same for different aliases? I'm asking because maybe it is possible to use some wildcard in the alias argument and then let the HttpServlet object deal with whatever comes in the HttpRequest...?

欢迎任何帮助/建议/想法!

Any help/suggestions/thoughts are welcome!

关于, 亚历克斯

推荐答案

我对OSGI知之甚少,但是在我看来,这更像是一个纯粹的servlet问题.我查看了您提供的链接,希望能为您提供帮助.

I don't know very much about OSGI, however it seems to me to be more a pure servlet problem. I took a look at the links you provided and hope I can help you.

首先,我认为您无需告诉HttpService它将接受参数.使用servlet时,只需提取请求参数即可:

First, I think you do not need to tell the HttpService that it will accept params. When you use servlets, you can simply extract the request parameters:

public void doGet(HttpServletRequest req, HttpServletResponse resp) 
        throws ServletException, IOException {
    req.getParameter(paramName); // get a request parameter
}

第二,我认为您可以将同一个Servlet用于多个别名".对我来说,这似乎是一种servlet映射:您可以为一个和同一个servlet使用多个映射(/helloworld/helloxyz等).

Second, I think you can use the same Servlet for multiple "aliases". This seems like a kind of servlet mapping to me: You can use multiple mappings (/helloworld, /helloxyz etc.) for one and the same servlet.

这篇关于在接收参数的OSGi中注册servlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆