Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Help on HTML

Posted on 2016-07-22
1
Medium Priority
?
100 Views
Last Modified: 2016-07-23
Hi Team,

Iam developing an application where in I need to integrate HTML with Servlets and servlets to interact with Database using JDBC and send the results back to HTML page withour refreshing it.

It would be of great help if anyone can help with an example . Iam new to Java related technologies.
0
Comment
Question by:sam_2012
1 Comment
 
LVL 54

Accepted Solution

by:
Scott Fell,  EE MVE earned 2000 total points
ID: 41725130
I am not a java developer and perhaps you need to break your question down to two parts.  One for the back end and one for the front.

On the front end, you want to use an ajax request to your back end page.

You can do this in pure javascript, I like to  use jquery
http://api.jquery.com/jquery.ajax/
$.ajax({
  method: "GET",   
  url: "processpage",
  data: { first: "hello", last: "world" }
})
  .done(function( data) {
    alert( data);
  });

Open in new window


On your processpage, accept the get just as if the page was processpage?first=hello&last=world

On your main page, make a page using code similar to what I have above
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.0.3.js"></script>
  <script>
    $(function(){
    $.ajax({
  method: "GET",   
  url: "processpage",
  data: { first: "hello", last: "world" }
})
  .done(function( data) {
    //alert( data);
      $('#results').html(data);
  })
    
});
  </script>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>test</title>
</head>
<body>
  <div id="results"></div>
</body>
</html>

Open in new window

When you run the code on the main page above and your other page called processpage can extract the url processpage?first=hello&last=world and output "hello world" you will see that text in the div id results.

How you connect to your database in your java page is another process.

If this makes sense you are good to go.  If not, take just one piece at a time before going on to the next.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A solution for Fortify Path Manipulation.
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question