Call JSP/Servlet from java program?

Discussions

Web tier: servlets, JSP, Web frameworks: Call JSP/Servlet from java program?

  1. Call JSP/Servlet from java program? (2 messages)

    Can a java program call a JSP or servlet, or EJB??

    Thank you.
  2. Yes, You use the URL class and point it to your
    servlet or JSP URL.

           InputStreamReader isr = new InputStreamReader(System.in ) ;
           BufferedReader br = new BufferedReader(isr);

           String line = br.readLine() ;

    URL url = new URL( "http://localhost:7001/reverse.jsp" ) ;

    URLConnection connection = url.openConnection() ;

    connection.setDoOutput(true) ;

    // The order in which input and output strams are acquired matters.
           ObjectOutputStream os = new ObjectOutputStream( connection.getOutputStream() ) ;

    os.writeObject( line ) ;
    os.close() ;

           ObjectInputStream is = new ObjectInputStream( connection.getInputStream() ) ;
           System.out.println( is.readObject() ) ;
    is.close() ;
  3. Call JSP/Servlet from java program?[ Go to top ]

    Yes, You use the URL class and point it to your
    servlet or JSP URL.

           InputStreamReader isr = new InputStreamReader(System.in ) ;
           BufferedReader br = new BufferedReader(isr);

           String line = br.readLine() ;

    URL url = new URL( "http://localhost:7001/reverse.jsp" ) ;

    URLConnection connection = url.openConnection() ;

    connection.setDoOutput(true) ;

    // The order in which input and output strams are acquired matters.
           ObjectOutputStream os = new ObjectOutputStream( connection.getOutputStream() ) ;

    os.writeObject( line ) ;
    os.close() ;

           ObjectInputStream is = new ObjectInputStream( connection.getInputStream() ) ;
           System.out.println( is.readObject() ) ;
    is.close() ;

    Hey man...

    I have a class SampleLogin.java. From SampleLogin.Login(), i should redirect call to a JSP, which loads applet, and read input from it and get the control back to SampleLogin.login(). How to achieve this??

    Suggestions are highly praised.