0

是否可以从放置在另一个项目中的 servlet 中对 EJBRemoteBean 进行分类?如何 ?我试过这个

第一个项目;

EJBRemoteBean.java

@Stateless
public class EJBRemoteBean implements EJBRemote {

    @Override
    public int addition( int x, int y ) {
        return x + y;
    }
}

EJBRemote.java

@Remote
public interface EJBRemote {
    public int addition( int x, int y );
}

第二个项目:

EJBServlet.java

public class EJBServlet extends HttpServlet {
    @EJB( mappedName = "com.ejb.session.stateless.EJBRemote" )
    private EJBRemote ejbr;

    protected void processRequest( HttpServletRequest request, HttpServletResponse response )
            throws ServletException, IOException {
        response.setContentType( "text/html;charset=UTF-8" );
        PrintWriter out = response.getWriter();
        out.println( "<html>" );
        out.println( "<head>" );
        out.println( "<title>Servlet EJBServlet</title>" );
        out.println( "</head>" );
        out.println( "<body>" );
        out.println( "<h1>EJBRemote.addition returned: " + ejbr.addition( 2, 3 ) + "</h1>" );
        out.println( "</body>" );
        out.println( "</html>" );
    }

    protected void doGet( HttpServletRequest request, HttpServletResponse response )
            throws ServletException, IOException {
        processRequest( request, response );
    }

    protected void doPost( HttpServletRequest request, HttpServletResponse response )
            throws ServletException, IOException {
        processRequest( request, response );
    }
}

我找不到如何修复此 servlet 以调用 EJBRemoteBean 的包含方法。请问有什么帮助吗?

提前致谢。

4

0 回答 0