[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 374
  • Last Modified:

If user auttheticated, go to welcome.jsp

I would like to get some help folks...I have a page login.jsp which allow the user to enter their user name and password. If the username and password are validated in the database, I would like the user to be redirected to a page called welcome.jsp..I have tried to use <jsp:forward page="welcome.jsp"> but it is giving me an error...Could you please give me a better idea?

This is my code;
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page import="java.sql.*"%>

<html>
<body>
<%
try
{

String user_input= request.getParameter("sUserName");
String pass_input= request.getParameter("sPwd");

String user_db=new String("");
String pass_db=new String("");


Connection con=null;
Statement s=null;
ResultSet rs=null;

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("Jdbc:Odbc:dB","","");
 s = con.createStatement( );

String sql = "SELECT Username,Password FROM Users WHERE Username='"+user_input+"'";

s.executeQuery (sql);
rs = s.getResultSet();


while (rs.next())
{
 user_db=rs.getString("Username");
 pass_db=rs.getString("Password");


 if


 (user_db.equals(request.getParameter("sUserName"))&&
 pass_db.equals(request.getParameter("sPwd")))
       {

        <jsp :forward page="welcome.jsp"> ////// This is where i am having the problem, the connection is perfect

       }

           else
              {

               out.println("You are not an authentic person");
               

              }


 }
rs.close();
s.close();
con.close();



 }

  catch(Exception e)
      {
 System.out.println("Exception is ;"+e);
      }


 %>

</body>
</html>

Open in new window

0
ozzyfanta
Asked:
ozzyfanta
  • 3
  • 3
  • 2
1 Solution
 
Sathish David Kumar NCommented:
can you tell what is the path of welcome.jsp

if in web content folder try /welcome.jsp

or ur /applicatiName/welocme.jsp
0
 
ozzyfantaAuthor Commented:
It is still giving me an error ...it is in web content. Do you really think the problem is not with <jsp: forward...> Do you know of any other way u can do that
0
 
ozzyfantaAuthor Commented:
This is the error:

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 44 in the jsp file: /doLogin.jsp
Syntax error on token(s), misplaced construct(s)
41:  pass_db.equals(request.getParameter("sPwd")))
42:        {
43:
44:        <jsp :forward page="/welcome.jsp">
45:
46:        }
47:


An error occurred at line: 44 in the jsp file: /doLogin.jsp
Syntax error, insert "AssignmentOperator Expression" to complete Assignment
41:  pass_db.equals(request.getParameter("sPwd")))
42:        {
43:
44:        <jsp :forward page="/welcome.jsp">
45:
46:        }
47:


An error occurred at line: 44 in the jsp file: /doLogin.jsp
Syntax error, insert ";" to complete Statement
41:  pass_db.equals(request.getParameter("sPwd")))
42:        {
43:
44:        <jsp :forward page="/welcome.jsp">
45:
46:        }
47:


An error occurred at line: 44 in the jsp file: /doLogin.jsp
forward cannot be resolved
41:  pass_db.equals(request.getParameter("sPwd")))
42:        {
43:
44:        <jsp :forward page="/welcome.jsp">
45:
46:        }
47:


An error occurred at line: 44 in the jsp file: /doLogin.jsp
Syntax error on token ">", ; expected
41:  pass_db.equals(request.getParameter("sPwd")))
42:        {
43:
44:        <jsp :forward page="/welcome.jsp">
45:
46:        }
47:


Stacktrace:
      org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
      org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
      org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
      org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:326)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rrzCommented:
Instead of using
><jsp :forward page="welcome.jsp">  
Please try using  the following lines instead.  
RequestDispatcher rd = request.getRequestDispatcher("welcome.jsp");
rd.forward(request,response);
0
 
rrzCommented:
> I would like the user to be redirected to a page called welcome.jsp  
If this is what you want then try using  
response.sendRedirect("welcome.jsp");  
This way it will say welcome.jsp in the browser's address bar.
With the forward it will still say doLogin.jsp
0
 
Sathish David Kumar NCommented:
oh my dear what is this ....  sorry i didnt c full code now only i notice ....

ur code is
 if   
  
 (user_db.equals(request.getParameter("sUserName"))&&  
 pass_db.equals(request.getParameter("sPwd"))) 

Open in new window




but ur colsing the if before && opertator ....

if (----> starting if hereloop here
 user_db.equals(request.getParameter("sUserName"))--------> ending here so that only its pblm  
0
 
Sathish David Kumar NCommented:
change your code like this ....  sorry iqnore my last comment

 if(user_db.equals(request.getParameter("sUserName"))&&   pass_db.equals(request.getParameter("sPwd")))  

dont give more sepace between code if and ur code

0
 
ozzyfantaAuthor Commented:
Thanks bro...it is working fine now. Just for correction, it is still saying doLogin.jsp but displays the welcome.jsp page...

Thanks a lot
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now