Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f4af16a

Browse files
practice code added
1 parent 3c5ec0e commit f4af16a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+30435
-0
lines changed

‎Practice/AjaxDemo.zip‎

2.59 MB
Binary file not shown.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<style>
4+
table,
5+
th,
6+
td {
7+
border: 1px solid black;
8+
border-collapse: collapse;
9+
}
10+
11+
th,
12+
td {
13+
padding: 5px;
14+
}
15+
</style>
16+
17+
<body>
18+
19+
<h2>The XMLHttpRequest Object</h2>
20+
21+
<button type="button" onclick="loadDoc()">Get my CD collection</button>
22+
<br><br>
23+
<table id="demo"></table>
24+
25+
<script>
26+
function loadDoc() {
27+
const xhttp = new XMLHttpRequest();
28+
xhttp.onload = function () {
29+
myFunction(this);
30+
}
31+
xhttp.open("GET", "cd_catalog.xml");
32+
xhttp.send();
33+
}
34+
function myFunction(xml) {
35+
const xmlDoc = xml.responseXML;
36+
const x = xmlDoc.getElementsByTagName("CD");
37+
console.log(x);
38+
let table = "<tr><th>Artist</th><th>Title</th></tr>";
39+
for (let i = 0; i < x.length; i++) {
40+
table += "<tr><td>" +
41+
x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue +
42+
"</td><td>" +
43+
x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue +
44+
"</td></tr>";
45+
}
46+
document.getElementById("demo").innerHTML = table;
47+
}
48+
</script>
49+
50+
</body>
51+
52+
</html>

‎Practice/AjaxDemo/Ajax-XML.html‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
<div id='showCD'></div><br>
5+
<input type="button" onclick="previous()" value="<<">
6+
<input type="button" onclick="next()" value=">>">
7+
8+
<script>
9+
var i = 0;
10+
var x;
11+
displayCD(i);
12+
13+
function displayCD(i) {
14+
var xmlhttp = new XMLHttpRequest();
15+
xmlhttp.onreadystatechange = function() {
16+
if (this.readyState == 4 && this.status == 200) {
17+
myFunction(this, i);
18+
}
19+
};
20+
xmlhttp.open("GET", "cd_catalog.xml", true);
21+
xmlhttp.send();
22+
}
23+
24+
function myFunction(xml, i) {
25+
var xmlDoc = xml.responseXML;
26+
x = xmlDoc.getElementsByTagName("CD");
27+
document.getElementById("showCD").innerHTML =
28+
"Artist: " +
29+
x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue +
30+
"<br>Title: " +
31+
x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue +
32+
"<br>Year: " +
33+
x[i].getElementsByTagName("YEAR")[0].childNodes[0].nodeValue;
34+
}
35+
36+
function next() {
37+
if (i < x.length-1) {
38+
i++;
39+
displayCD(i);
40+
} }
41+
42+
function previous() {
43+
if (i > 0) {
44+
i--;
45+
displayCD(i);
46+
} }
47+
</script>
48+
</body>
49+
</html>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
5+
<h2>JavaScript Callbacks</h2>
6+
7+
<p id="demo"></p>
8+
9+
<script>
10+
function myDisplayer(some) {
11+
document.getElementById("demo").innerHTML = some;
12+
}
13+
14+
function getFile(myCallback) {
15+
let req = new XMLHttpRequest();
16+
req.open('GET', "mycar.html");
17+
req.onload = function() {
18+
if (req.status == 200) {
19+
myCallback(this.responseText);
20+
} else {
21+
myCallback("Error: " + req.status);
22+
}
23+
}
24+
req.send();
25+
}
26+
27+
getFile(myDisplayer);
28+
</script>
29+
30+
</body>
31+
</html>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
5+
<h2>JavaScript setInterval()</h2>
6+
7+
<p>Using setInterval() to display the time every second (1000 milliseconds).</p>
8+
9+
<h1 id="demo"></h1>
10+
11+
<script>
12+
setInterval(myFunction, 1000);
13+
14+
function myFunction() {
15+
let d = new Date();
16+
document.getElementById("demo").innerHTML=
17+
d.getHours() + ":" +
18+
d.getMinutes() + ":" +
19+
d.getSeconds();
20+
}
21+
</script>
22+
23+
</body>
24+
</html>
2.35 KB
Binary file not shown.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import java.io.IOException;
2+
import java.io.PrintWriter;
3+
import java.sql.Connection;
4+
import java.sql.DriverManager;
5+
import java.sql.PreparedStatement;
6+
import java.sql.ResultSet;
7+
import javax.servlet.ServletException;
8+
import javax.servlet.http.HttpServlet;
9+
import javax.servlet.http.HttpServletRequest;
10+
import javax.servlet.http.HttpServletResponse;
11+
12+
public class EmployeeServlet extends HttpServlet {
13+
14+
protected void doGet(HttpServletRequest request, HttpServletResponse response)
15+
throws ServletException, IOException
16+
{
17+
response.setContentType("text/html;charset=UTF-8");
18+
19+
PrintWriter out = response.getWriter();
20+
String ss=request.getParameter("q");
21+
22+
String url = "jdbc:mysql://localhost:3306/ajaxdemo";
23+
String user = "root";
24+
String password = "ssn@123";
25+
try{
26+
//2. Load JDBC Driver and register the driver
27+
Class.forName("com.mysql.cj.jdbc.Driver").newInstance();
28+
29+
System.out.println("Hey I am after forname method");
30+
31+
//3. Open a Connection
32+
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/ajaxdemo?allowPublicKeyRetrieval=true&useSSL=false",user,password);
33+
//Connection conn = DriverManager.getConnection(url,user,password);
34+
System.out.println("con--->"+con);
35+
36+
PreparedStatement ps=con.prepareStatement("select * from ajaxemployee where name=?");
37+
System.out.println("Hey I am after prepared statement");
38+
ps.setString(1,ss);
39+
ResultSet rs=ps.executeQuery();
40+
if(rs.next()){
41+
out.println("name is already existing");
42+
}
43+
else
44+
out.println("name doesnot already exist");
45+
46+
}
47+
catch(Exception e)
48+
{
49+
e.printStackTrace();
50+
}
51+
52+
}
53+
54+
55+
}
2.3 MB
Binary file not shown.
96.9 KB
Binary file not shown.

‎Practice/AjaxDemo/WEB-INF/web.xml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
3+
<servlet>
4+
<servlet-name>EmployeeServlet</servlet-name>
5+
<servlet-class>EmployeeServlet</servlet-class>
6+
</servlet>
7+
<servlet-mapping>
8+
<servlet-name>EmployeeServlet</servlet-name>
9+
<url-pattern>/s</url-pattern>
10+
</servlet-mapping>
11+
<session-config>
12+
<session-timeout>
13+
30
14+
</session-timeout>
15+
</session-config>
16+
</web-app>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /