opening new html pages
1 posts in topic
Flat View  Flat View

Posted By:   nikunj_murgai
Posted On:   Tuesday, March 12, 2002 09:29 AM

if i have a servlet .thru which i enter a password and username ..i want that if the password and username match with what i had saved then the nxt page say ...new.html is displayed and else the same page is displayed again say ol.html.......how can i do this ...
thanks in advance

Re: opening new html pages

Posted By:   Jorge_Perez  
Posted On:   Wednesday, March 13, 2002 10:17 AM

Hi Nikunj!

Let's see what you can do here is, if you are writing all the HTML stuff in your servlet is, create a validation routine that returns some kinda flag so you know the l/p did or didn't match adn using a simple if.. else... can do the trick.

probably if you are gonna output a good amount of HTML adding a pair of JSP pages can be good as well, my example:

public doPost (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

public void doLogin(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
int isValid = -1;
String login = req.getParameter("ID");
String passwd = req.getParameter("pwd");
isValid = validate(login, passwd);
if (isValid == 0){
RequestDispatcher rd =
rd.include(req, res);} else {
RequestDispatcher rd =
rd.include(req, res);
private int validate(String a, String b)
/*Insert here your routine for login validation, can be through JDBC, or using JNI with an LDAP server, or such */
int i = 0;
return (i);

If you plan to use this with JSPs just change the dispatcher toforward (rd.forward(req, res)) instead of rd.include(req, res). Also note the code above is not well built, just wrote it on the fly for a short example.

Let me know if this was of help.


About | Sitemap | Contact