• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

Need help wwith jsp error

Taking a class to learn jsp.  Why I keep getting this error here, http://csci5xx.usc.edu:8860/login.jsp
I don't see any syntax error for the <%@ include...  Please help.  Thanks.

also, what's the best way to set my errMsg for the <span> tag I have.  Javascript?  Thanks.
<%
	String uid=request.getParameter("uid");
	String pw = request.getParameter("pw");
	if(uid == null) uid="";
	if(pw == null) pw="";	
%>

<%@ Include file="loginheader.html" %>

<span id='msg'></span>
<%
	if(uid!="" && pw!="")
	{

		string x='Login information incorrect!';
		//go to database to validate user login%>  
		<p> Validate user</p>
		<!-- Step 1, load the jdbc driver-->
		<% try{
				class.forName("com.mysql.jdbc.driver").newInstance();

		     <//tep 2, Create the Connection object and connect to the sql server

				String connectionString = "jdbc:mySql://server/dbname";
				Connection myConnection = DriverManager.getConnection(connectionString, 'user', 'pass');
				session.setAttribute("myConnection");

			// Step 3, Execut query

					Statement s = null;
					ResultSet rs = null;
					s = myConnection.CreateStatement();
					sqlText = "select * from User where userid = '" + uid + "' and password = '" pw +"'";
					rs = s.ExecutQuery(sqlText);

			if(rs.next)
			{
				String userType;
				userType = rs.getString("userType");					
				if(userType == 1 //Rediret to Admin.jsp	
				{
					session.setAttribute( "uid", uid );
					session.setAttribut("userType", userType);
					session.setMaxInactiveInterval(300);							
					response.sendRedirect("admin.jsp");
				}
				else if(userType == 2 //Redirect to Employee.jsp								
					response.sendRedirect("employee.jsp");
			}
			else
			{
				var errMsg = "Login error!";
			}
			
		}
	%>
 	
<%@ Include file="loginfooter.html" %>

Open in new window

0
lapucca
Asked:
lapucca
  • 8
  • 2
1 Solution
 
rrzCommented:
<%@ Include file="loginheader.html" %>
try
<%@ include file="loginheader.html" %>
0
 
rrzCommented:
again
<%@ Include file="loginfooter.html" %>  
try
<%@ include file="loginfooter.html" %>
0
 
rrzCommented:
>string x='Login information incorrect!';  
try
String x = "Login information incorrect!";
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
rrzCommented:
>session.setAttribute("myConnection");  
Not a good idea.
Just use it and close it when you are finished.  
myConnection.close();  
0
 
rrzCommented:
Add import if you don't have it already.
<%@ page import="java.sql.* %>
0
 
rrzCommented:
>if(userType == 1 //Rediret to Admin.jsp      
>else if(userType == 2 //Redirect to Employee.jsp
instead  use  
if("1".equals(userType)) //Rediret to Admin.jsp      
else if("2".equals(userType)) //Redirect to Employee.jsp
bye for now.
0
 
rrzCommented:
one more
>session.setAttribut("userType", userType);  
session.setAttribute("userType", userType);
0
 
lapuccaAuthor Commented:
Hi, I've made the changes you pointed out, except for the close connection. We were instructed to keep it open so we can use it at other pages. Do you think it's better to open it as I need it at each page?
also, now I get new error about, String uid = request.getParameter("uid");
which I can't see the problem either. BTW, it took me a minute or so to realize the include's i was cap.
Thank you.
<%@ page import="java.sql.* %>
<%
	String uid = request.getParameter("uid");
	String pw = request.getParameter("pw");
	if(uid == null) uid="";
	if(pw == null) pw="";	
%>
<%@ include file="loginheader.html" %>

<span id='msg'></span>
<%
	if(uid!="" && pw!="")
	{
		//go to database to validate user login%>  
		<p> Validate user</p>
		<!-- Step 1, load the jdbc driver-->
		<% try{
				class.forName("com.mysql.jdbc.driver").newInstance();

		     <//tep 2, Create the Connection object and connect to the sql server

				String connectionString = "jdbc:mySql://server/dbname";
				Connection myConnection = DriverManager.getConnection(connectionString, 'user', 'password');
				session.setAttribute("myConnection");
				

			// Step 3, Execut query

					Statement s = null;
					ResultSet rs = null;
					s = myConnection.CreateStatement();
					sqlText = "select * from User where userid = '" + uid + "' and password = '" pw +"'";
					rs = s.ExecutQuery(sqlText);

			if(rs.next)
			{
				String userType;
				userType = rs.getString("userType");					
				if(userType == 1 //Rediret to Admin.jsp	
				{
					session.setAttribute( "uid", uid );
					session.setAttribut("userType", userType);
					session.setMaxInactiveInterval(300);							
					response.sendRedirect("admin.jsp");
				}
				else if(userType == 2 //Redirect to Employee.jsp								
					response.sendRedirect("employee.jsp");
			}
			else
			{
				String x = "Login information incorrect!";				
			}
			
		}
	%>
 	
<%@ include file="loginfooter.html" %>

Open in new window

0
 
lapuccaAuthor Commented:
Thank you.
0
 
rrzCommented:
>We were instructed to keep it open so we can use it at other pages.
Its ok for testing. But, in real web site with many users, you might have a problem.  
Thanks for the points.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

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