• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jsp vs rmi

 
Ranch Hand
Posts: 39
MyEclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I call the rmi methods from jsp.

After running the following jsp shows the error given below the code.

=======================================================================
<html>
<head>
<title>JSP and RMI</title>
</head>
<body>
<%@ page import='java.rmi.*' %>
<%@ page import='java.rmi.Naming' %>
<%@ page import='server1.*' %>
<%@ page import='interface1.*' %>
<%@ page import='java.lang.*' %>

<%
try
{
RajaService rp=(RajaService)Naming.lookup("rmi://localhost/RajaService");
out.println("5 sqare is : "+rp.sqare(5));
}
catch(Exception ex){out.println(ex.getMessage());}

%>

</body>
</html>

==========================================================================
Error is
====================
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 12 in the jsp file: /RSCJSP.jsp
Generated servlet error:
The method sqare(int) is undefined for the type RajaService


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:397)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.

==========================================================
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As pointed out to you elsewhere, it's much better design to do this kind of thing in a backing bean or a servlet than in a JSP.

Anyway, does the RajaService class have a square(int) method?
 
Rajasekhar Pentakota
Ranch Hand
Posts: 39
MyEclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes RajaService has sqare method.

The followingis the Interface RajaService


======================
package interface1;

import java.rmi.RemoteException;

//
// PowerService Interface
//
// Interface for a RMI service that calculates powers
//
public interface RajaService extends java.rmi.Remote
{
// Calculate the square of a number
public int square ( int number )
throws RemoteException;

}
============================
The following code is Server class which implements the RajaService

========================
package server1;

import java.math.*;
import java.rmi.*;
import java.rmi.server.*;
import interface1.RajaService;


public class RajaServiceServer extends UnicastRemoteObject implements RajaService
{
public RajaServiceServer() throws RemoteException
{
super();
}

// Calculate the square of a number
public int square ( int number )
throws RemoteException
{
return number * number;
}


public static void main ( String args[] ) throws Exception
{
// Assign a security manager, in the event that dynamic
// classes are loaded
if (System.getSecurityManager() == null)
System.setSecurityManager ( new RMISecurityManager() );

RajaServiceServer svr = new RajaServiceServer();

Naming.bind ("RajaService", svr);

System.out.println ("Service bound....");
}
}
=========================================================
 
Rajasekhar Pentakota
Ranch Hand
Posts: 39
MyEclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The bean class code is

=====================================================

package client1;

import java.rmi.*;
import java.io.*;
import server1.RajaServiceServer;
import interface1.RajaService;

public class RajaJspServiceClient
{

public int getsq(int sq) throws Exception
{
if (System.getSecurityManager() == null)
{
System.setSecurityManager
(new RMISecurityManager());
}

// Call registry for PowerService
RajaService service = (RajaService) Naming.lookup
("rmi://localhost/RajaService");

return service.square(sq);

}

}
=====================================================

and the jsp code is

========================================================
<html>
<head>
<title>JSP and RMI</title>
</head>
<body>
<%@ page import='java.rmi.*' %>
<%@ page import='java.rmi.Naming' %>
<%@ page import='server1.*' %>
<%@ page import='interface1.*' %>
<%@ page import='java.lang.*' %>

<jsp:useBean id="counter" scope="request" class="client1.RajaJspServiceClient" />

<%
out.println("Welcome...");
out.println("The sqare of 10 is : " + counter.getsq(10));
%>



</body>
</html>

====================================================================
reply
    Bookmark Topic Watch Topic
  • New Topic