Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7608419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:54:31+00:00 2026-05-31T00:54:31+00:00

Ok, so I’m learning web design as a co-op at a company. However, the

  • 0

Ok, so I’m learning web design as a co-op at a company. However, the department I’m in is lacking in knowledgeable people in web design. So here we go…

Building a site that will allow the department to manage PTO. I want to implement ajax b/c the main page will have a calendar system so the manager can view the PTO week by week. As a precursor to that, I’m attempting to implement ajax with the “add Employee” page for practice.
However, I can’t seem to figure out what I’m missing (aka, why it’s not doing anything)

This page just needs to add the new employee to the database. No display needed.

The main page just has 4 text fields and I get the information from those fields in javascript like so

    var firstName = document.getElementById("firstNameField");
var lastName = document.getElementById("lastNameField");
var manager = document.getElementById("managerField");
var networkID = document.getElementById("networkIDField");

Simple enough so far.

So I set up the ajax code like so, (this is gathered from what I’ve read.

 var url = "addEmpJSP.jsp?firstNameField=" +   escape(firstName)+"&lastNameField="+escape(lastName)+"&managerField="+escape(manager)+"&networkIDField="+escape(networkID);
  xmlhttp.open("POST",url,true);
  xmlhttp.onreadystatechange=dummy;
  xmlhttp.send(null);

This is the part where I’m assuming it’s correct as I’m still learning ajax and how it works. I don’t think I need to handle a response as I simply want the called jsp file to automatically do whats needed. (if that’s possible).

The jsp file looks like this

<%

ResultSet rsEmpl;
Connection connection1 = getDBConnection();
Statement statment1=connection1.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);

String fName = request.getParameter("firstNameField");
String lName = request.getParameter("lastNameField");
String manager = request.getParameter("managerField");
String networkID = request.getParameter("networkIDField");
Int empId = 0;

String EditEmplSQL = "select * from PTO_employee";
rsEmpl=statment1.executeQuery(EditEmplSQL);


rsEmpl.last();
empId = rsEmpl.getRow() - 1;


statement1.execute("INSERT INTO PTO_employee VALUES ("+empID+","+lName+","+fName+","+0+","+2+","+networkID);

%>

I have a button on the page that executes the javascript function that contains the ajax info. I’m avoiding jquery atm b/c I’m trying to understand this stuff and how it works before I attempt to use “shortcuts” like jquery. I’m working towards a degree in Software Engineering so understanding this stuff is my priority, not getting it done.(that’s just a bonus) If you need anymore information I can provide it. Sorry for my lack of knowledge and if this is completely off base then 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:54:32+00:00Added an answer on May 31, 2026 at 12:54 am

    The main page just has 4 text fields and I get the information from those fields in javascript like so

    var firstName = document.getElementById("firstNameField");
    var lastName = document.getElementById("lastNameField");
    var manager = document.getElementById("managerField");
    var networkID = document.getElementById("networkIDField");
    

    That gives you whole HTML DOM elements back, not the values of those elements. HTML DOM elements are like Java classes, having properties, methods and so on. Assuming that it are HTML input elements like <input>, then use their value property instead to get the value. So:

    var firstName = document.getElementById("firstNameField").value;
    var lastName = document.getElementById("lastNameField").value;
    var manager = document.getElementById("managerField").value;
    var networkID = document.getElementById("networkIDField").value;
    

    So I set up the ajax code like so, (this is gathered from what I’ve read.

    var url = "addEmpJSP.jsp?firstNameField=" +   escape(firstName)+"&lastNameField="+escape(lastName)+"&managerField="+escape(manager)+"&networkIDField="+escape(networkID);
    xmlhttp.open("POST",url,true);
    xmlhttp.onreadystatechange=dummy;
    xmlhttp.send(null);
    

    The escape() is the wrong function. It escapes JS syntax, it does not encode URI components. You should be using encodeURIComponent() function instead.


    The jsp file looks like this

    ...
    Int empId = 0;
    ...
    

    This doesn’t compile. It should be int instead.

    ...
    String EditEmplSQL = "select * from PTO_employee";
    rsEmpl=statment1.executeQuery(EditEmplSQL);
    rsEmpl.last();
    empId = rsEmpl.getRow() - 1;
    ...
    

    Unnecessarily overcomplicated. Learn how to use DB builtin sequences/autoincrement IDs. Refer the DB specific manual or ask DB admin for help.

    ...
    statement1.execute("INSERT INTO PTO_employee VALUES ("+empID+","+lName+","+fName+","+0+","+2+","+networkID);
    ...
    

    You should put quotes around string values in the SQL query. Assuming that lName, fName and networkID are strings, not numbers, then it should look like this:

    statement1.execute("INSERT INTO PTO_employee VALUES (" + empID + ",'" + lName + "','" + fName + "'," + 0 + "," + 2 + ",'" + networkID + "'");
    

    But you have there a huge SQL injection attack hole and you also don’t seem to close DB resources at all after use, so they may leak away and cause your webapp to crash sooner or later because the DB runs out of resources. Use PreparedStatement to create a parameterized SQL query and use its setters to set the values. Close the resources in finally block.

    After all, reading the server logs should provide you information about compile errors and any server exceptions. Reading the ajax response should provide you information about the response status and body. Your core problem was that you ignored it and thus didn’t have any chance to understand what is happening.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.