Yes, you should not use
return (name=="abc" && passwd=="123 ");
but
return (name.equals("abc") && passwd.equals("123"));
This will probably fix your problem.
Johan
----- Original Message -----
From: "Roland Dong" <[EMAIL PROTECTED]>
To: "Orion-Interest" <[EMAIL PROTECTED]>
Sent: Sunday, April 01, 2001 11:42 AM
Subject: Please help me figure out this....
>
> I have login.html calling a servlet (loginHander) which handles
authorization. If user is validated, the servlet will redirect the user to
Welcome.jsp
>
> My problem is I could not pass the value of user and password from
login.html to loginHandler. I set the boolean method loggedIn so that when
user name is
> abc and password is 123 the user should log in. However, this somehow can
not be accomplished. Even I entered abc as name and 123 as password, I was
bounced back to login.html page.
>
> I am using Orion 1.47.
>
> Please help!
>
> RB
>
> //Here is loginHander.java
>
> import java.io.*;
> import java.util.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class LoginHandler extends HttpServlet {
>
> public void doPost(HttpServletRequest req, HttpServletResponse res)
> throws ServletException, IOException {
> res.setContentType("text/html");
> PrintWriter out = res.getWriter();
>
> // Get the user's name and password
> String name = req.getParameter("name");
> String passwd = req.getParameter("passwd");
>
> // Check the name and password for validity
> if (!loggedIn(name, passwd)) {
> out.println("<HTML><HEAD><TITLE>Access Denied</TITLE></HEAD>");
> out.println("<BODY>Your login and password are invalid.<BR>");
> out.println("You may want to <A HREF=\"/jsp/testing/login.html\">try
again</A>");
> out.println("</BODY></HTML>");
> }
> else {
> // Valid login. Make a note in the session object.
> HttpSession session = req.getSession(true);
> session.setAttribute("logon.isDone", name); // just a marker object
>
> // Try redirecting the client to the page he first tried to access
> try {
>
> res.sendRedirect("/jsp/testing/Welcome.jsp");
> return;
>
>
> }
> catch (Exception ignored) { }
>
> // Couldn't redirect to the target. Redirect to the site's home
page.
> res.sendRedirect(req.getScheme() + "://" +
> req.getServerName() + ":" + req.getServerPort());
> }
> }
>
> protected boolean loggedIn(String name, String passwd) {
>
> return (name=="abc" && passwd=="123 ");
>
> }
> }
>
> //********************************
> //Here is the login.html
>
> <HTML>
> <TITLE>Login</TITLE>
> <BODY>
> <FORM ACTION=/servlet/LoginHandler METHOD=POST>
> <CENTER>
> <TABLE BORDER=0>
> <TR><TD COLSPAN=2>
> <P ALIGN=CENTER>
> Welcome! Please enter your NnnnName<br>
> and Password to log in.
> </TD></TR>
>
> <TR><TD>
> <P ALIGN=RIGHT><B>Name:</B>
> </TD>
> <TD>
> <P><INPUT TYPE=TEXT NAME="name" VLAUE="" SIZE=15>
> </TD></TR>
>
> <TR><TD>
> <P ALIGN=RIGHT><B>Password:</B>
> </TD>
> <TD>
> <P><INPUT TYPE=PASSWORD NAME="passwd" VALUE="" SIZE=15>
> </TD></TR>
>
> <TR><TD COLSPAN=2>
> <CENTER>
> <INPUT TYPE=SUBMIT VALUE=" OK ">
> </CENTER>
> </TD></TR>
> </TABLE>
> </BODY></HTML>
>
>
> //*****************************************
> //Here is the Welcom.jsp
>
>
> <% if ( session.getValue("userName") == null) { %>
>
> <B> hello...it is a null<B>
>
> <% // here we can give some error message %>
>
> <% } else {%>
>
> <!------- so this is the authorized user let's display the welcome
> message --- >
>
> <HTML>
>
> <HEAD>
>
> <B> Welcome <%= session.getValue("userName")%>
>
> </B>
>
> </HEAD>
>
> <BODY>
>
> <!--- all the other stuff -->
>
> </BODY>
>
> </ HTML>
>
> <% } %>
>