Beruflich Dokumente
Kultur Dokumente
WEBSERVICE
→ xposing it XML
Eg: webservice
currency converter
Elements of webservice:
1) Install JWSDP
download → exe file
1) JWSDP_HOME
c:\jwsdp-2.0
2) CATALINE_HOME
c:\Tomcat50-jwsdp
3) CLASS_PATH
c:\Tomcat . . . .\lib\servlet-api.jar
Writing a WS:
1) Create a folder c:\Hellomessage with web-INF inside and two more folders name src and
classes
[[***Art***]]
java.rmi.Remote interface
[[***Art***]]
MyInterface.java
5) package hellomsg;
import.java.rmi.RemoteException;
5) C:\HelloMessage\web-inf> javac-d.classes
6) package hellomsg;
MyInterface
[[***Art***]]
<?xml>
<configuration mlns = “http://java.oracle.com/xml/ns/jax-rpc/ri/config>
</configuration>
9) c:\hellomessage\
config.xml
gz compressed file
10) c:\HelloMessage\WEB-INF\jaxrpc-ri.xml
11) <?xml>
nance of the var file to be deployed web archive file collection of different web tech file.
</webservice>
web.xml
c:\HelloMessage>“jar cf Hello-temp.rar
WEB-INF
Cf = create file
C:\Hellomessage>wsdeploy-o
Hello.war Hello-temp.war
Consume the WS
1) Creating WS client
[[***Art***]]
Source config.xml
stub → webservices
Classes:
→ MyInterface_stub
Hellomsgclient – java
import javax.servlet.*;
import javax.servlet.http.*;
Exception_Io Exception
println (s);
3) Running:
xml → Hellomsgclient
http://localhost:8080/HelloMsgClient
WSDL
It is based on xml
It is used to desc the webserv and the method for accusing it.
It is W3C recommendation
Elements:
No response one-way
<types/>
</message>
</operations>
</port type>
<input>
</input>
<output>
</output>
</binding>
</definition>
SOAP
→ Based xml
→ w3c std.
Structure:
[[***Art***]]
Fault: [optional]
<m: Getdetails>
</m. Getdetails>
</SOAP-ENV: body>
</SOAP-ENV: Envelope>
9 rows selected.
/**
* Web service operation
*/
@WebMethod(operationName = "getInfo")
public String getInfo(@WebParam(name = "src")
String src, @WebParam(name = "dest")
String dest) {
String str="";
try
{Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("inside testdb");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@//192.168.9.185:1521/cse","system","ma
nager");
Statement s=con.createStatement();
if(src.equals("mumbai"))
{
if(dest.equals("pune"))
s.executeQuery("SELECT * FROM airways_table WHERE Start_from='mumbai' AND
Dest='pune'");
else if(dest.equals("chennai"))
s.executeQuery("SELECT * FROM airways_table WHERE Start_from='mumbai' AND
Dest='chennai'");
}
else if(src.equals("pune"))
{
if(dest.equals("mumbai"))
s.executeQuery("SELECT * FROM airways_table WHERE Start_from='pune' AND
Dest='mumbai'");
else if(dest.equals("chennai"))
s.executeQuery("SELECT * FROM airways_table WHERE Start_from='pune' AND
Dest='chennai'");
}
else if(src.equals("chennai"))
{
if(dest.equals("pune"))
s.executeQuery("SELECT * FROM airways_table WHERE Start_from='chennai' AND
Dest='pune'");
else if(dest.equals("Mumbai"))
s.executeQuery("SELECT * FROM airways_table WHERE Start_from='chennai' AND
Dest='mumbai'");
}
ResultSet rs=s.getResultSet();
str+="<table border=1>";
while(rs.next())
{
str+="<tr><b>";
str+="<td>";
str+=rs.getString("name");
str+="</td>";
str+="</tr></b>";
}
str+="</table>";
}catch(ClassNotFoundException ex)
{
System.out.println(ex);
}
catch(SQLException ex)
{
System.out.println(ex);
}
return str;
}
}
3.CONSTRUCT AIRLINE RESERVATION CLIENT
a)index.jsp
<html>
<head>
<title>AIRLINE RESERVATION SYSTEM</title>
</head>
<body bgcolor=”khaki”>
<center>
<h4>Travel Agent should fill up following information to get information about the
Airline</h4>
<form name=”form1” method=GET action =”reserve.jsp”>
<table>
<tr>
<td><b>Source city: </b></td>
<td><input type=”text” name=”Src_name” size=”20” value=””></td>
</tr>
<tr>
<td><b>Destination city: </b></td>
<td><input type=”text” name=”Dest_name” size=”20” value=””></td>
</tr>
<tr>
<td><input type=”submit” value=”Submit”></td>
</tr>
</table>
</form>
</center>
</body>
</html>
b)reserve.jsp
<%
try {
air.TestDB_Service service =new air.TestDB_Service();
air. TestDB port = service.get TestDB Port();
String result = port.get(a1, a2);
%>
<%
} catch (Exception ex) {
ex.printStackTrace();
}
%>
AIRLINE RESERVATION
Result is
Airline Seat Confirmation
indian airlines
british airways
AJAX
What is AJAX?
• AJAX stands for Asynchronous Javascript And XML
• AJAX is not a programming language
• AJAX is a way of using existing standards (JavaScript and XML) to make more interactive web
applications
• AJAX was popularized in 2005 by Google (with Google suggest)
An AJAX Application
• Recall the standard HTTP transaction
1. Client opens connection to server
2. Client sends request to server
3. Server sends reply to client
4. Client and server close connection
• After Step 4, the client renders the document and this may include running some JavaScript
• In an AJAX application, the JavaScript code then communicates with the server behind the scenes.
Communication with the server takes place asynchronously, and transparently to the user
• Data is exchanged with the server without the need for a page reload
• This is accomplished through a special kind of HTTP request
EXAMPLE
In this page, we have created a form that gets input from the user. When user clicks on the showTable
button, sendInfo() function is called. We have written all the ajax code inside this function.
We have called the getInfo() function whenever ready state changes. It writes the returned data in the web page
dynamically by the help of innerHTML property.
table1.html
<html>
<head>
<script>
var request;
function sendInfo()
{
var v=document.vinform.t1.value;
var url="index.jsp?val="+v;
if(window.XMLHttpRequest){
request=new XMLHttpRequest();
}
else if(window.ActiveXObject){
request=new ActiveXObject("Microsoft.XMLHTTP");
}
try
{
request.onreadystatechange=getInfo;
request.open("GET",url,true);
request.send();
}
catch(e)
{
alert("Unable to connect to server");
}
}
function getInfo(){
if(request.readyState==4){
var val=request.responseText;
document.getElementById('amit').innerHTML=val;
}
}
</script>
</head>
<body>
<marquee><h1>This is an example of ajax</h1></marquee>
<form name="vinform">
<input type="text" name="t1">
<input type="button" value="ShowTable" onClick="sendInfo()">
</form>
<span id="amit"> </span>
</body>
</html>
index.jsp
<%
int n=Integer.parseInt(request.getParameter("val"));
for(int i=1;i<=10;i++)
out.print(i*n+"<br>");
%>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>table1.html</welcome-file>
</welcome-file-list>
</web-app>
Advantages of AJAX
AJAX Concept
Before you starting AJAX you'll need to have a strong knowledge of JavaScript. AJAX is not a difficult, you can
easy implement AJAX in a meaningful manner. Some IDE are help us to implement AJAX.
Speed
Reduce the server traffic in both side request. Also reducing the time consuming on both side response.
Interaction
AJAX is much responsive, whole page(small amount of) data transfer at a time.
XMLHttpRequest
XMLHttpRequest has an important role in the Ajax web development technique. XMLHttpRequest is special
JavaScript object that was designed by Microsoft. XMLHttpRequest object call as a asynchronous HTTP
request to the Server for transferring data both side. It's used for making requests to the non-Ajax pages.
Asynchronous calls
AJAX make asynchronous calls to a web server. This means client browsers are avoid waiting for all data
arrive before start the rendering.
Form Validation
This is the biggest advantage. Form are common element in web page. Validation should be instant and
properly, AJAX gives you all of that, and more.
Bandwidth Usage
No require to completely reload page again. AJAX is improve the speed and performance. Fetching data from
database and storing data into database perform background without reloading page.
Disadvantages of AJAX
1. AJAX application would be a mistake because search engines would not be able to index an AJAX
application.
2. Open Source: View source is allowed and anyone can view the code source written for AJAX.
3. ActiveX requests are enabled only in Internet Explorer and newer latest browser.
4 The last disadvantage, XMLHttpRequest object itself. For a security reason you can only use to access
information from the web host that serves initial pages. If you need to fetching information from another server,
it's is not possible with in the AJAX.