gpt4 book ai didi

java - 无法在 Servlet 中查找 RMI 服务器

转载 作者:太空宇宙 更新时间:2023-11-04 14:20:59 26 4
gpt4 key购买 nike

我无法从 RMI servlet 查找对象!

错误是:(无安全管理器:RMI 类加载器已禁用)

服务器代码:

public class CrecheServer {

/**
* @param args the command line arguments
* @throws java.rmi.RemoteException
* @throws java.rmi.AlreadyBoundException
*/
public static void main(String[] args) throws RemoteException, AlreadyBoundException {
Registry registry = LocateRegistry.createRegistry(7700);
Metodo metodo = new Metodo();
registry.bind("RMI", metodo);
System.out.println("Servidor Ativo!");
}

}

客户端上的 Servlet:

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, RemoteException, NotBoundException, ParseException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
Registry reg = LocateRegistry.getRegistry("127.0.0.1", 7700);
Metodo metodo = (Metodo) reg.lookup("RMI");
String nome = request.getParameter("nome");
String sexo = request.getParameter("sexo");
String dtNascimento = request.getParameter("dtNascimento");
String cpf = request.getParameter("cpf");
String telefone = request.getParameter("tel");
String logradouro = request.getParameter("logradouro");
String quadra = request.getParameter("quadra");
metodo.CadastroResponsavel(nome, sexo, dtNascimento, cpf, telefone, logradouro, quadra);
request.setAttribute("url", "sucesso");
RequestDispatcher r = request.getRequestDispatcher("index.jsp");
r.forward(request, response);

}
}

我在客户端和服务器上有接口(interface)和类。这是行不通的:

            Metodo metodo = (Metodo) reg.lookup("RMI");

最佳答案

我修好了!类methodo的包名在客户端不同

关于java - 无法在 Servlet 中查找 RMI 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27205096/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com