Monday, 4 January 2016

WEB SERVICES

In src package, code the following java code in file Server:


package com;

import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;


@WebService(serviceName = "Server")
public class Server {

    /**
     * This is a sample web service operation
     */
    @WebMethod(operationName = "hello")
    public String hello(@WebParam(name = "name") String txt) {
        return "Hello " + txt + " !";
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "Sum")
    public int Sum(@WebParam(name = "a") int a, @WebParam(name = "b") int b) {
        //TODO write your implementation code here:
        return a+b;
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "Subtract")
    public int Subtract(@WebParam(name = "a") int a, @WebParam(name = "b") int b) {
        //TODO write your implementation code here:
        return a-b;
    }
}

2. In file index in web package, code the following:
   

package com;

import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;


@WebService(serviceName = "Server")
public class Server {

    /**
     * This is a sample web service operation
     */
    @WebMethod(operationName = "hello")
    public String hello(@WebParam(name = "name") String txt) {
        return "Hello " + txt + " !";
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "Sum")
    public int Sum(@WebParam(name = "a") int a, @WebParam(name = "b") int b) {
        //TODO write your implementation code here:
        return a+b;
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "Subtract")
    public int Subtract(@WebParam(name = "a") int a, @WebParam(name = "b") int b) {
        //TODO write your implementation code here:
        return a-b;
    }
}

MINI PROJECT BOOK DETAILS

IN src package ,code the following files:

1. AddBookServlet

package com;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet(name = "AddBookServlet", urlPatterns = {"/AddBookServlet"})
public class AddBookServlet extends HttpServlet {

     protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        try {
            if (request.getParameter("sbtnAddBook") != null) {
                String title = request.getParameter("txtTitle");
                String price = request.getParameter("txtPrice");
//               String msg = new Service().addRec(title, Double.parseDouble(price));
                response.sendRedirect("ManageBook.jsp");

            }
        } finally {
            out.close();
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response);
    }
}

   2. In AddEditBookBean code the following:

package com;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet(name = "AddBookServlet", urlPatterns = {"/AddBookServlet"})
public class AddBookServlet extends HttpServlet {

     protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        try {
            if (request.getParameter("sbtnAddBook") != null) {
                String title = request.getParameter("txtTitle");
                String price = request.getParameter("txtPrice");
//               String msg = new Service().addRec(title, Double.parseDouble(price));
                response.sendRedirect("ManageBook.jsp");

            }
        } finally {
            out.close();
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response);
    }
}

   3. In authServelt code the following:

package com;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "AuthServlet", urlPatterns = {"/AuthServlet"})
public class AuthServlet extends HttpServlet {
     protected void processResquest(HttpServletRequest resquest,HttpServletResponse response) throws ServletException,IOException
    {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out=response.getWriter();
        try{
            RequestDispatcher rd=null;
           
            if(resquest.getParameter("sbtnLogin")!=null){
                String un=resquest.getParameter("txtUsername");
                String pwd=resquest.getParameter("txtPassword");
               
                if(un.trim().equals("admin") && pwd.trim().equals("admin")){
                    rd=resquest.getRequestDispatcher("ManageBook.jsp");
                    rd.forward(resquest, response);
                }
                else{
                   
                    out.println("<p style=\"color:red\">Invalid username and password</p>");
                    rd=resquest.getRequestDispatcher("Login.html");
                    rd.include(resquest, response);
                }
               
            }
        }
       
        finally{
            out.close();
        }
    }
    @Override
    protected  void  doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
        processResquest(request, response);
    }
    @Override
    protected  void  doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
        processResquest(request, response);
    }
   
           
   
}

   

INTRODUCTION TO JAVA EE

Java Platform, Enterprise Edition or Java EE is a widely used enterprise computing platform developed under the Java Community Process. The platform provides an API and runtime environment for developing and running enterprise software, including network and web services, and other large-scale, multi-tiered, scalable, reliable, and secure network applications. Java EE extends the Java Platform, Standard Edition (Java SE),[1] providing an API for object-relational mapping, distributed and multi-tier architectures, and web services. The platform incorporates a design based largely on modular components running on an application server. Software for Java EE is primarily developed in the Java programming language. The platform emphasizes convention over configuration[2] and annotations for configuration. Optionally XML can be used to override annotations or to deviate from the platform defaults.

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes