Iterative
Name Server Implementation Using Java Server Pages
Main.jsp:
<form
method = "post" action = "dns.jsp" target =
"_blank">
<input
type = "text" name = "dn" />
<input
type = "button" value = "Search on DNS" onclick =
"submit();self.close();" />
</form>
Dns.jsp:
<%@
page import="java.sql.*" %>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dn = request.getParameter("dn");
try{
Connection con =
DriverManager.getConnection("jdbc:odbc:server","scott","tiger");
PreparedStatement ps = con.prepareStatement("select addr from dns
where dn='"+dn+"'");
ResultSet rs = ps.executeQuery();
rs.next();
String addr = rs.getString(1);
%>
<form
method = "post" action = "<%=addr%>" target =
"_blank">
<input type = "button" value =
"Go to Site" onclick = "submit()" />
</form>
<%
ps.close();
}
catch(SQLException
e)
{
%>Domain
address Not available<%
}
%>
Google.jsp:
Welcome to Google
Yahoo.jsp:
Welcome
to Yahoo
Facebook.jsp:
Welcome
to Facebook
Output:
Procedure to create and
insert values into table dns :
SQL>
create table dns(dn varchar2(20), addr varchar2(50));
Table
created.
SQL>
insert into dns
values('google.com','http://localhost/Progs/NameServer/google.jsp');
1
row created.
SQL>
insert into dns
values('yahoo.com','http://localhost/Progs/NameServer/yahoo.jsp');
1
row created.
SQL>
insert into dns values('facebook.com','http://localhost/Progs/NameServer/facebook.jsp');
1
row created.
SQL>
select * from dns;
DN ADDR
--------------------
--------------------------------------------------
google.com
http://localhost/Progs/NameServer/google.jsp
yahoo.com
http://localhost/Progs/NameServer/yahoo.jsp
facebook.com
http://localhost/Progs/NameServer/facebook.jsp
SQL> commit;
Commit complete.