Calling HttpServlet class from xpages client side script and regular notes forms?

拥有回忆 提交于 2020-01-06 07:32:09

问题


I am new (again, have not touched it in a while) to Java.

I have a simple (much more complex one is planned) HttpServlet class that I am tryng to call from a webpage either from a regular Notes form or csjs on an xPage.

package com.pnc.cld;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloWorld extends HttpServlet
{
    private static final long serialVersionUID = -2950148158748149L;

    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
        System.out.println("doGet: Hello World!");
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
        System.out.println("doPost: Hello World!"); 
    }
}

I found this article here.

Which is orginally in Chinese so it makes it a bit hard to follow but from what I have been able to glean from it, you need a add a IServletFactory class which maps the servlet to your a url so it can be called in your browser.

But I am getting errors. This article fixed some of them

But I still still get a number of errors. One of them:

The type ServletFactory must implement the inherited abstract method IServletFactory.getServletMatch(String, String) ServletFactory.java

Also the article seems to say that you need to add com.ibm.xsp.adapter.servletFactory to the services directory but I can't find the file anywhere on my PC.

Are there any better articles or hopefully working example for calling an httpservlet out there?


回答1:


Bruce, on Domino you need to implement a servlet OSGi style. Go steal the code from my webDAV for Domino project on OpenNTF. The servlet is definitely working!




回答2:


Maybe you should study the sample database from Sven's blog post. Switch the Domino Designer to the Java perspective and have a look at the "Code/Java" section. There you find 3 files. One of them handles the URLs and maps them to the servlet. The third one is stored within the META-INF folder and defines where the IServletFactory should lookup the ServletFactory class (the second file). The first file ist the servlet itself. But careful: we just got stuck with errors in the sample database, too. Pretty simple cause: in the servlet code a "static" exception is thrown :-D Remove that code and you are fine. We tested this on a 8.5.3 machine but I am sure it will do on older releases, too.



来源:https://stackoverflow.com/questions/15226268/calling-httpservlet-class-from-xpages-client-side-script-and-regular-notes-forms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!