Howto: call a Servlet from another Servlet (Example)?!

2010-09-20 Thread Michael Stockhausen
Hello,

I have create two Servlets (LoginServlet  UserListServlet).
I'm using a JSP for the User credentials. When you press the login-button,
the LoginServlet is called.

I would like to call the UserListServlet, when the username and password are
correct.

How can I call UserListServle from the doGet(...) function of the
LoginServlet. I would like to call a Servlet from another servlet.

Where can I find some examples?

Thanks,
Michael


Re: Howto: call a Servlet from another Servlet (Example)?!

2010-09-20 Thread Laurence L Leff

- Original Message -
From: Michael Stockhausen prof.dr.moe...@googlemail.com

I have create two Servlets (LoginServlet  UserListServlet).
I'm using a JSP for the User credentials. When you press the login-button,
the LoginServlet is called.

I would like to call the UserListServlet, when the username and password are
correct.

Where can I find some examples?

Thanks,
Michael
 I teach this in my Graphical User Interface Programming class:  
(http://www.wiu.edu/users/mflll/CS412g/n3x.xml.pdf)

  URL url = new URL(http://toolman.wiu.edu:14096/servlet/OurData;);
  InputStream openStream = url.openStream();
  InputStreamReader r = new InputStreamReader(openStream);
  char buf[] = new char[1];
  r.read(buf,0,1);

One just starts the servlet by invoking it with a URL and reading from the  
stream.

I may have seen this in the Servlet Programming  by Jason Hunter and William 
Crawford.

Dr. Laurence Leff  Western Illinois University, Macomb IL 61455 ||(309) 298-1315
Stipes 447 Assoc. Prof. of Computer Sci. Pager: 309-367-0787 FAX: 309-298-2302 

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Howto: call a Servlet from another Servlet (Example)?!

2010-09-20 Thread Ronald Klop

You can use the RequestDispatcher.

RequestDispatcher dispatcher = request.getRequestDispatcher(/userlist);
dispatcher.forward(request, response);

Google gives you a lot of examples.

Ronald.



Op maandag, 20 september 2010 16:47 schreef Michael Stockhausen 
prof.dr.moe...@googlemail.com:


 


Hello,

I have create two Servlets (LoginServlet  UserListServlet).
I'm using a JSP for the User credentials. When you press the login-button,
the LoginServlet is called.

I would like to call the UserListServlet, when the username and password are
correct.

How can I call UserListServle from the doGet(...) function of the
LoginServlet. I would like to call a Servlet from another servlet.

Where can I find some examples?

Thanks,
Michael








Re: Howto: call a Servlet from another Servlet (Example)?!

2010-09-20 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Ronald,

On 9/20/2010 11:07 AM, Ronald Klop wrote:
 You can use the RequestDispatcher.
 
 RequestDispatcher dispatcher = request.getRequestDispatcher(/userlist);
 dispatcher.forward(request, response);

Of course, you can also issue a redirect to the client:

response.sendRedirect(...)

The advantage of issuing a redirect is that the client will not have to
re-authenticate if the user then RELOADs the resulting page.

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkyXf3gACgkQ9CaO5/Lv0PDRmQCfSKPGx2EbXA8dA0WlcbNee8M9
/YYAoJ6iHtoM5pYzteMy3DMHzH07OCno
=bBF7
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



RE: Howto: call a Servlet from another Servlet (Example)?!

2010-09-20 Thread Leo Donahue - PLANDEVX


-Original Message-
From: Christopher Schultz [mailto:ch...@christopherschultz.net]
Subject: Re: Howto: call a Servlet from another Servlet (Example)?!

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Ronald,

On 9/20/2010 11:07 AM, Ronald Klop wrote:
 You can use the RequestDispatcher.

 RequestDispatcher dispatcher =
request.getRequestDispatcher(/userlist);
 dispatcher.forward(request, response);

Of course, you can also issue a redirect to the client:

response.sendRedirect(...)

The advantage of issuing a redirect is that the client will not have to
re-authenticate if the user then RELOADs the resulting page.

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkyXf3gACgkQ9CaO5/Lv0PDRmQCfSKPGx2EbXA8dA0WlcbNee8M9
/YYAoJ6iHtoM5pYzteMy3DMHzH07OCno
=bBF7
-END PGP SIGNATURE-

I thought that if you were making a request to a UserListServlet and it was 
restricted to authentication, assuming you use Form Authentication and 
structure your login form correctly, you don't have to worry about calling 
LoginServlet or using the requestDispatcher?  Doesn't Tomcat handle this for 
you?  What am I missing here?

In the OP question, to what does the LoginServlet authenticate you?  The 
LoginServlet?  


Re: Howto: call a Servlet from another Servlet (Example)?!

2010-09-20 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Leo,

On 9/20/2010 12:55 PM, Leo Donahue - PLANDEVX wrote:
 I thought that if you were making a request to a UserListServlet and
 it was restricted to authentication, assuming you use Form
 Authentication and structure your login form correctly, you don't
 have to worry about calling LoginServlet or using the
 requestDispatcher?  Doesn't Tomcat handle this for you?  What am I
 missing here?

 In the OP question, to what does the LoginServlet authenticate you?
 The LoginServlet?

- From my reading, the OP is doing his own authentication rather than
using container-managed authentication.

If he /is/ using container-managed authentication, then he's using it
incorrectly :)

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkyXpakACgkQ9CaO5/Lv0PCQ1QCginz5lDgSDCX/U6ek3oEQXvgg
pdwAoKP12wnSztLoujxoj7rvNY8N4u/3
=r7fJ
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



RE: Howto: call a Servlet from another Servlet (Example)?!

2010-09-20 Thread Leo Donahue - PLANDEVX
Chris,

-Original Message-
From: Christopher Schultz [mailto:ch...@christopherschultz.net]
Subject: Re: Howto: call a Servlet from another Servlet (Example)?!

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

- From my reading, the OP is doing his own authentication rather than
using container-managed authentication.

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkyXpakACgkQ9CaO5/Lv0PCQ1QCginz5lDgSDCX/U6ek3oEQXvgg
pdwAoKP12wnSztLoujxoj7rvNY8N4u/3
=r7fJ
-END PGP SIGNATURE-

I thought rolling your own authentication, rather than using container-managed 
security for authentication, is a bad idea?  Is that just rhetoric?


Re: Howto: call a Servlet from another Servlet (Example)?!

2010-09-20 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Leo,

On 9/20/2010 3:05 PM, Leo Donahue - PLANDEVX wrote:
 Chris,
 
 -Original Message- From: Christopher Schultz
 [mailto:ch...@christopherschultz.net] Subject: Re: Howto: call a
 Servlet from another Servlet (Example)?!
 
 - From my reading, the OP is doing his own authentication rather
 than using container-managed authentication.
 
 -chris

 I thought rolling your own authentication, rather than using
 container-managed security for authentication, is a bad idea?  Is
 that just rhetoric?

That's a matter of perspective.

I'd recommend using container-managed authentication and authorization
to pretty much everybody. Or, failing that, at least use a library meant
for doing such things, like ACEGI or securityfilter: the folks in charge
of those projects have taken care to be spec-compliant (to the extent
possible and/or desired) and properly test their products to ensure that
they are safe.

Rolling your own authentication mechanism often leads to an insecure
system. It's also usually not necessary: container-managed security
works very well for most people, and the new servlet 3.0 changes to
authentication even (I believe) allow the webapp to request
authentication under certain other circumstances.

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkyXt/QACgkQ9CaO5/Lv0PBbEgCffmnSHPKJ12KCZmspuv0CdcWY
H5gAoLm4Yrwym1elDFvmFs+y0yta6+8P
=no35
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Howto: call a Servlet from another Servlet (Example)?!

2010-09-20 Thread Pid
On 20/09/2010 16:00, Laurence L Leff wrote:
 
 - Original Message -
 From: Michael Stockhausen prof.dr.moe...@googlemail.com
 
 I have create two Servlets (LoginServlet  UserListServlet).
 I'm using a JSP for the User credentials. When you press the login-button,
 the LoginServlet is called.
 
 I would like to call the UserListServlet, when the username and password are
 correct.
 
 Where can I find some examples?
 
 Thanks,
 Michael
  I teach this in my Graphical User Interface Programming class:  
 (http://www.wiu.edu/users/mflll/CS412g/n3x.xml.pdf)
 
   URL url = new URL(http://toolman.wiu.edu:14096/servlet/OurData;);
   InputStream openStream = url.openStream();
   InputStreamReader r = new InputStreamReader(openStream);
   char buf[] = new char[1];
   r.read(buf,0,1);
 
 One just starts the servlet by invoking it with a URL and reading from the  
 stream.

Ermm...

I'm not really sure that's what he's looking for.


p



0x62590808.asc
Description: application/pgp-keys


signature.asc
Description: OpenPGP digital signature


RE: Howto: call a Servlet from another Servlet (Example)?!

2010-09-20 Thread George Sexton




 -Original Message-
 From: Leo Donahue - PLANDEVX [mailto:leodona...@mail.maricopa.gov]
 Sent: Monday, September 20, 2010 10:56 AM
 To: 'Tomcat Users List'
 Subject: RE: Howto: call a Servlet from another Servlet (Example)?!
 
 
 
 -Original Message-
 From: Christopher Schultz [mailto:ch...@christopherschultz.net]
 Subject: Re: Howto: call a Servlet from another Servlet (Example)?!
 
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1
 
 Ronald,
 
 On 9/20/2010 11:07 AM, Ronald Klop wrote:
  You can use the RequestDispatcher.
 
  RequestDispatcher dispatcher =
 request.getRequestDispatcher(/userlist);
  dispatcher.forward(request, response);
 
 Of course, you can also issue a redirect to the client:
 
 response.sendRedirect(...)
 

Please make sure that any examples of respond.sendRedirect() or 
RequestDispatcher.forward() are IMMEDIATELY followed by a return statement 
because neither of those statements terminates the calling servlet's 
processing. IOW, processing chugs right along. This can cause very strange 
problems. It can also expose potential security problems because often you're 
redirecting to a login page. If you don't terminate processing, the code 
further along can assume the user is authenticated.

 The advantage of issuing a redirect is that the client will not have
 to
 re-authenticate if the user then RELOADs the resulting page.
 
 - -chris
 -BEGIN PGP SIGNATURE-
 Version: GnuPG v1.4.10 (MingW32)
 Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
 
 iEYEARECAAYFAkyXf3gACgkQ9CaO5/Lv0PDRmQCfSKPGx2EbXA8dA0WlcbNee8M9
 /YYAoJ6iHtoM5pYzteMy3DMHzH07OCno
 =bBF7
 -END PGP SIGNATURE-
 
 I thought that if you were making a request to a UserListServlet and it
 was restricted to authentication, assuming you use Form Authentication
 and structure your login form correctly, you don't have to worry about
 calling LoginServlet or using the requestDispatcher?  Doesn't Tomcat
 handle this for you?  What am I missing here?
 
 In the OP question, to what does the LoginServlet authenticate you?
 The LoginServlet?

George Sexton
MH Software, Inc.
303 438-9585
www.mhsoftware.com


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org