0

I have HttpServlet class called, let's call is Test. I can output anything from this class using HttpServletResponse object into my html page. Now, I have another a plain java class, let's call it Home, and in this class I need to out put something into the html page. Unfortunately, it doe snot work even I have tried to inherit HttpServlet from Home class and use HttpServletResponse object to out put.

Is there a way to redirect the output from the Home class to Test class ?

Here's the method doGetof my Test class, it create an object of home and call the method connectToHom() for authentication.

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws  ServletException, IOException {
       String tst = "username"
        tst = new Home();
        tst.connectToHome(tst); 

}

Here's the method connectToHome() of the class Home:

public void connectToHome(String tst){
  -> Try to login using tst,
  connect = Connection.open(tst);

  if(connect.getMessage()!=null){
    System.out.println("-- Error: " + connect.getMessage()); 
    return null;
 }
}

The above code works but it prints out on the console instead on the html page.

Thanks in advance!

2
  • Please post some code. Commented Oct 16, 2014 at 20:56
  • Hi Boris, I have post the code. Thanks! Commented Oct 16, 2014 at 21:20

1 Answer 1

2

you need to send an OutputStream ref. to Home class:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws  ServletException, IOException {
    String tst = "username"
    tst = new Home();
    tst.connectToHome(tst, response.getOutputStream());   
}


public void connectToHome(String tst, OutputStream out){
  -> Try to login using tst,
  connect = Connection.open(tst);

  if(connect.getMessage()!=null){
    out.print("-- Error: " + connect.getMessage() + "\n"); 
    out.flush();
    return null;
 }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Hi, tahnk you! I will try that out and let you know. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.