Sie sind auf Seite 1von 4

Department of Software Engineering, Web services, III year I sem

Project name: Book Store Web Application using JAVA Web services Time: 15 days

Book store: A book Store wants to expose all the information about the books available with them
through a web application.
Prepare a java web service [BookService.java
[ (Service)] to expose the data.(Service)
.(Service)
For the book store you need to prepare a jsp application which uses a java web service.
service.(Client)

The steps you will take to produce and test your project using web services are as follows:

1. Create a project in the Eclipse workspace of type 'Dynamic Web Project', which will host your
web service.
2. Write the Java code (the 'business logic') that implements your web service functionality.
3. Use Eclipse to automatically generate the components (WSDL
(WSDL etc.) that will transform the Java
code into a web service.
4. Create another project of type 'Dynamic Web Project', which will host the client application that
you will use to access and test the web service.
5. Use Eclipse to automatically generate a client
clie interface to call the web service.
6. Use the jsp client to send requests to the web service to have a web application as follows.

Book Store Web Application using JAVA Web services Page 1


Department of Software Engineering, Web services, III year I sem
Project name: Book Store Web Application using JAVA Web services Time: 15 days

BookService.java (Service)
Data for book store
package com.wolkite.se.lab;

public class BookService {

static String []book={"c++","java","web service","mobile programming"};


static String []author={"c++ author","java author","web service author","mobile programming
author"};
static int []price={200,300,500,120};

public static String getBook(String authorName)


{
int i=0;
for(;i<author.length;i++)
{
if(authorName.equals(author[i]))
break;
}

if(i>=author.length)
return "no book with the author";
else
return book[i];
}

public static String getAuthor(String bookName)


{
int i=0;
for(;i<book.length;i++)
{
if(bookName.equals(book[i]))
break;
}

if(i>=book.length)
return "no author with the book";
else
return author[i];
}

public static String[] getAllBook()


{
return book;
}

public static String[] getAllAuthor()


{
return author;

Book Store Web Application using JAVA Web services Page 2


Department of Software Engineering, Web services, III year I sem
Project name: Book Store Web Application using JAVA Web services Time: 15 days

public static int[] getAllPrice()


{
return price;
}

public static int getPrice(String bookName)


{
int i=0;
for(;i<book.length;i++)
{
if(bookName.equals(book[i]))
break;
}

if(i>=book.length)
return 0;
else
return price[i];
}
}

Sample jsp for find author

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"


pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1> Book Store</h1>

<form action="getbook.jsp" method="post">


enter book name:<input type="text" name="value1" value="">
<input type="submit" value="Find author">
</form>

<%@page import="java.util.*"%>
<%@page import="java.rmi.RemoteException"%>
<%@page import="com.wolkite.se.lab.*" %>

<%

java.net.URL endpointUrl=new
java.net.URL("http://localhost:8080/BookStoreService/services/BookService");
org.apache.axis.client.Service service=new org.apache.axis.client.Service();
BookServiceSoapBindingStub stub=new BookServiceSoapBindingStub(endpointUrl,service);
String bname=request.getParameter("value1");

Book Store Web Application using JAVA Web services Page 3


Department of Software Engineering, Web services, III year I sem
Project name: Book Store Web Application using JAVA Web services Time: 15 days

if(bname!=null)
{
String result=stub.getAuthor(bname);

%>
The Author name is: <%=result%>

<%} %>

</body>
</html>

Sample code for find all book jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"


pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<h1>Book Store</h1>
<%@page import="java.util.*"%>
<%@page import="java.rmi.RemoteException"%>
<%@page import="com.wolkite.se.lab.*" %>

<%

java.net.URL endpointUrl=new
java.net.URL("http://localhost:8080/BookStoreService/services/BookService");
org.apache.axis.client.Service service=new org.apache.axis.client.Service();
BookServiceSoapBindingStub stub=new BookServiceSoapBindingStub(endpointUrl,service);

String[] result=stub.getAllBook();
int i=0;
%>
<table border=1>
<tr><th>All Books</th></tr>
<%
for(;i<result.length;i++)
{
%> <tr><td>
<%=result[i]%> </td>
<%} %></table>

</body>
</html>

Book Store Web Application using JAVA Web services Page 4

Das könnte Ihnen auch gefallen