0

I am developing a code in Netbeans 6.7. In my code there is a jsp page that contains a form. This form sends the entered details to a servlet called Client.java. I am trying to run an RMI program in the servlet. I have created the classes Server.java and the interface also.
i want to know how do you run an RMI program in Netbeans, how to create the stub and start the registry through netbeans.
There is nothing wrong with the program as i have stored it separately and run it through DOS prompt also. It runs properly.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by itit
0

Little of google search and you would find this nice entry from Code Ranch

thank u. i had already seen that. i just wanted to know if there was any way to run it using the usual method of using Naming class and stuff. I have another doubt. can we use methods of other classes in the implementation class? If so, den how does one do that?

when i execute the following code it gives me a NullPointerException. plz help.

this is the client class

public class DigitalClient 
{
	public static void main(String args[])
	{
		try
		{
			Scanner s = new Scanner(System.in);
			s.useDelimiter("\n");
			System.out.println("enter your message ");
			String msg = s.next();
			System.out.println("enter billboard no");
			int board = 1;
			//s.nextInt();
			String s1 = s.next();
			System.out.println(s1);
			DigitalInterface di = (DigitalInterface)Naming.lookup("digital");
			System.out.println("looking up");
			di.addMessage(msg,board);
		}
		catch(RemoteException re)
		{
			re.printStackTrace();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
}

the implementation class :

public class DigitalServer extends UnicastRemoteObject implements DigitalInterface
{
	public DigitalServer()	throws RemoteException
	{
	}
	
	
	public void addMessage(String msg,int board)
	{
		DigitalBillboard db = new DigitalBillboard();
		int result = db.addMessage(msg,board);
		if(result == 0)
			System.out.println("Your message has been added. It will be displayed on billboard at " + db.getLocation(board));
		else
		{
			System.out.println("Message long");
			System.out.println("there is space only for "+result + " characters");
		}	
	}

	public static void main(String args[])
	{
		try
		{
			DigitalServer ds = new DigitalServer();
			Naming.rebind("digital",ds);
			System.out.println("server is ready");
		}
		catch(RemoteException re)
		{
			re.printStackTrace();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
}

this is DigitalBillboard - the class whose methods need to be called in the implementation class

public class DigitalBillboard extends Billboard
{
	 String message[];
	 int charSize[];
	 int maxChars[];
	public DigitalBillboard()
	{
		message = new String[5];
		charSize[0] = 10;
		charSize[1] = 15;
		charSize[2] = 10;
		charSize[3] = 15;
		charSize[4] = 10;

		maxChars[0] = 100;
		maxChars[1] = 150;
		maxChars[2] = 100;
		maxChars[3] = 150;
		maxChars[4] = 100;
		
		for(int i=0;i<5;i++)
			message[i] = "";
	}


	public int addMessage(String msg,int board)
	{
		System.out.println("billboard add message called");
		String space;
		int b = board -1;
		if(b==0 || b == 2 || b == 4)
			space = "          ";	
		else
			space = "               ";
		
		message[b] = message[b] + space;
		if((message[b].length() + msg.length() ) <= maxChars[b])
		{
			message[b] = message[b] + msg;
			return 0;
		}
		else
			return (maxChars[b] - message[b].length());
		
	}

Edited by peter_budo: Keep It Clear - Do wrap your programming code blocks within [code] ... [/code] tags

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.