Solved

Help on HTML

Posted on 2016-07-22
1
73 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 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

777 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