By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,626 Members | 1,929 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,626 IT Pros & Developers. It's quick & easy.

Error in my code

P: 18
Sometime back I had a posted an issue here. I was adviced to use AJAX in my application. I was not aware of it, somehow i managed to use it in. Now its working except few small issues. If anyone could find wats wrong, i will be greatful.

This contains 3 fields username,password and project. As the user enters his username,it calls the jsp thru ajax to fetch the project names. But the problem here is.. Its fetching the data but teking more time. And the user cannot know wat its doing. It shows as if its hanged. And then the project list box arrives but its not aligned properly. Adnd after the user selects the project name, and if he clicks on login,the project option gets changed to default automatically. And after pressing the login after teking a long time,it goes to next page.

Please anyone help me as its very important in my application. My code is here.

This is the login screen(login.jsp) wat i have so far..
[HTML]<html>
<body>
<head>
<link rel="stylesheet" href="css/Login.css"></link>
<script type="text/javascript">
function ajaxFunction(s)
{
var xmlHttp;
try
{ // Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{ // Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{

document.getElementById("abc").innerHTML =xmlHttp.responseText;
}
}
var url="untitled6.jsp?a="+s;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

</script>
</head>
<body>
<div id="box">
<h3>Please enter your ID and Password to login</h3><br><br>
<form name="f1" action="Hide1.jsp" onSubmit="return check(this)">
<table>
<tr><td>Employee Name</td>
<td><input type="text" onkeyup="ajaxFunction(this.value);" name="username" /></td>
</tr>
<tr>
<td>Password<font color="orange" size="5"></font></td>
<td><input type="password" name="password" class="mandatory" maxlength="10"/></td>
</tr>
</table>
<span id="abc"> </span>
<input type="submit" value="Login" class="button" name="cmdok" /> &nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" value="Exit" class="button" onClick="window.close();" name="cmdexit"/>
</form>
</body>
</html>
[/HTML]
And here is the jsp page untitled6.jsp

Expand|Select|Wrap|Line Numbers
  1. <%@ page import="java.sql.*" %>
  2. <%@ page import="javax.sql.*" %>
  3. <%@ page import="java.lang.*" %>
  4. <%@ page import="java.lang.Object.*" %>
  5. <%@ page import="java.io.*" %>
  6. <%@ page import="java.util.*" %>
  7. <%  
  8.        String name=request.getParameter("a");   
  9.        String empid="";
  10.        List a=new ArrayList();
  11.        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");       
  12.        Connection con1 = DriverManager.getConnection("jdbc:odbc:sujay","timesheet","timesheet");
  13.        Statement st= con1.createStatement();
  14.        ResultSet rs = st.executeQuery("SELECT * FROM TS_EMPLOYEE");
  15.        while(rs.next())
  16.        {       
  17.          empid= rs.getString("EMP_ID");       
  18.        }
  19.        out.println("<table><tr><td>Project: </td><td><select name='prj' STYLE='width:145px'><option selected>Default</option>");
  20.        ResultSet rss=st.executeQuery("select ts_project.prj_name,ts_project.prj_id from TS_PROJECT,ts_projectteam where ts_project.prj_id=ts_projectteam.prj_id and ts_projectteam.emp_id='"+empid+"'");
  21.        while(rss.next())       
  22.        a.add(rss.getString(1)); 
  23.        for(int i=0;i<a.size();i++)
  24.        out.println("<option>"+a.get(i)+"</option>");
  25.        out.println("</select></td></tr></table>");
  26. %>
Jun 22 '07 #1
Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
You're passing the username, but you're not even using it in your JSP code.

The query shouldn't get every single employee, it should try to match with the username.
Jun 22 '07 #2

P: 18
You're passing the username, but you're not even using it in your JSP code.

The query shouldn't get every single employee, it should try to match with the username.
Ya i got this point.
But after clicking login button, before it goes to next page, the list box value is getting changed to default automatically. Please give me the solution for this.. And one more thing is, Is there any way to make the ajax (or this piece of code) work faster
Jun 22 '07 #3

acoder
Expert Mod 15k+
P: 16,027
That might have something to do with your 'check' function which you call onsubmit. Maybe you could post that (in code tags) or at least check it yourself.

One other thing: give your select options values.
Jun 22 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.