Click here to Skip to main content
15,890,512 members
Home / Discussions / Java
   

Java

 
Questionjsp Pin
mohanbc1827-Oct-15 23:29
mohanbc1827-Oct-15 23:29 
GeneralRe: jsp Pin
Richard MacCutchan27-Oct-15 23:36
mveRichard MacCutchan27-Oct-15 23:36 
AnswerRe: jsp Pin
mohanbc1827-Oct-15 23:42
mohanbc1827-Oct-15 23:42 
GeneralRe: jsp Pin
Richard MacCutchan28-Oct-15 0:31
mveRichard MacCutchan28-Oct-15 0:31 
GeneralJava or JavaScript AKA where to start Pin
Vaclav_27-Oct-15 5:03
Vaclav_27-Oct-15 5:03 
GeneralRe: Java or JavaScript AKA where to start Pin
Richard MacCutchan27-Oct-15 5:26
mveRichard MacCutchan27-Oct-15 5:26 
GeneralRe: Java or JavaScript AKA where to start Pin
Vaclav_27-Oct-15 16:11
Vaclav_27-Oct-15 16:11 
QuestionJava RMI - chat app Pin
dzstef24-Oct-15 8:14
dzstef24-Oct-15 8:14 
XML
Hi everyone,
I would be grateful if someone help me with next problem that i have in Java:
Thing that i want to do is to make client-server chat app on web. I am using RMI. I will show just important class for my problem..
Here is mu server interface:

<pre lang="java">public interface ChatServerIF extends Remote {
//void registerChatClient(ChatClientIF chatClient) throws RemoteException;
//void broadcastMessage(String message) throws RemoteException;
void registerClient(String ime, ChatClientIF chatKlijent) throws RemoteException;
void posaljiPoruku(String ime, String poruka) throws RemoteException;
void dodajWeb(String naziv, PrintWriter print) throws RemoteException;
void pronadjiWeb(String naziv) throws RemoteException;
}


server class:

Java
public class ChatServer extends UnicastRemoteObject implements ChatServerIF {
public static final long serialVersionUID = 1L;
private HashMap<String, ChatClientIF> hmap = new HashMap<String, ChatClientIF>();
private Map<String, PrintWriter> web = new HashMap<String, PrintWriter>();
public List<HttpServletResponse> lista = new ArrayList<HttpServletResponse>();
public ChatServer() throws RemoteException{
//chatClients = new ArrayList<ChatClientIF>();
}
@Override
public synchronized void dodajWeb(String naziv, PrintWriter print) throws RemoteException{
web.put(naziv, print);
}
@Override
public void pronadjiWeb(String naziv) throws RemoteException {
//JspWriter pisi = web.get(naziv);
}


and part of servlet:

Java
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet IgraServlet</title>");
out.println("</head>");
out.println("<body>");
String username = request.getParameter("username");
ChatServerIF chat = (ChatServerIF) request.getSession().getAttribute("server");
ChatClient cc = (ChatClient) request.getSession().getAttribute("klijent");
//ChatServer cs = (ChatServer) request.getSession().getAttribute("cs");
PrintWriter pw = (PrintWriter) request.getSession().getAttribute("out");
chat.dodajWeb(username, pw);
cc.run();
out.println("aaa");

out.println("<h1>Servlet IgraServlet at " + request.getContextPath() + "</h1>");
out.println("</body>");
out.println("</html>");
}


My idea is to store user and PrintWritter for that user, from web page on server in order i can later sent message to that client.
Am i thinking good, or completely wrong?

But problem comes when i call chatServer interface method on servlet "chat.dodajWeb(username, pw)" i got next error:
java.rmi.MarshalException: error marshalling arguments; nested exception is:
java.io.NotSerializableException: java.io.PrintWriter
Please help me i try to search solution on internet, but for now without result..

Questionsolution for project Pin
Member 1208332323-Oct-15 22:57
Member 1208332323-Oct-15 22:57 
AnswerRe: solution for project Pin
Richard MacCutchan24-Oct-15 0:36
mveRichard MacCutchan24-Oct-15 0:36 
QuestionHomework help Pin
Member 1207437620-Oct-15 12:04
Member 1207437620-Oct-15 12:04 
AnswerRe: Homework help Pin
Peter Leow20-Oct-15 21:29
professionalPeter Leow20-Oct-15 21:29 
AnswerRe: Homework help Pin
Richard MacCutchan20-Oct-15 21:39
mveRichard MacCutchan20-Oct-15 21:39 
AnswerRe: Homework help Pin
Richard Deeming21-Oct-15 1:51
mveRichard Deeming21-Oct-15 1:51 
QuestionRe: Homework help Pin
Paul Conrad24-Oct-15 14:26
professionalPaul Conrad24-Oct-15 14:26 
QuestionCan we use a Bag class in a BST? Pin
Member 1205037111-Oct-15 8:17
Member 1205037111-Oct-15 8:17 
AnswerRe: Can we use a Bag class in a BST? Pin
Richard MacCutchan12-Oct-15 23:18
mveRichard MacCutchan12-Oct-15 23:18 
Questionjava Pin
Member 1205023611-Oct-15 6:34
Member 1205023611-Oct-15 6:34 
AnswerRe: java Pin
Richard MacCutchan11-Oct-15 21:21
mveRichard MacCutchan11-Oct-15 21:21 
AnswerRe: java Pin
KDGOLE13-Oct-15 18:31
KDGOLE13-Oct-15 18:31 
AnswerRe: java Pin
Jameshandra2-Nov-15 19:42
Jameshandra2-Nov-15 19:42 
QuestionNewbie to forum, and JAVA - Question Pin
Member 120400297-Oct-15 4:39
Member 120400297-Oct-15 4:39 
AnswerRe: Newbie to forum, and JAVA - Question Pin
Richard MacCutchan7-Oct-15 5:07
mveRichard MacCutchan7-Oct-15 5:07 
QuestionJava beginner question Pin
mjs585-Oct-15 15:44
mjs585-Oct-15 15:44 
AnswerRe: Java beginner question Pin
Richard MacCutchan5-Oct-15 20:51
mveRichard MacCutchan5-Oct-15 20:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.