Advanced Java Assignment writing Help from TutorsPoint

Tutorspoint is an excellent site, which caters to all queries regarding advance java assignment help to students and provides quality solutions.

Since the Java Assignment writing help is offered at reasonable rates, it is highly recommended site by many students across worldwide.

Send the documents with specifications along with the due dateyou will get all the authentic solutions from the specialists on the java subject.

 

HTTP Servlet interface

The various http servlet interfaces used are:

HttpServletRequest - The ServletRequest interface provides request information for HTTP servlets.

HttpServletResponse - the ServletResposeinterface provides HTTP-specific functionality in sending a response.

HttpSession – It is a way used identify a user across more than one page request or visit to a Web site and also to store information about that user.

HttpSessionActivationListener - Objects that are bound to a session listen to container events. The sessions will be passivated or activated.

HttpSessionAttributeListener – Within this web application, this listener interface can be implemented in order to get notifications of changes.

HttpSessionBindingListener – It causes an object to be notified when it is bound to or unbound from a session.

HttpSessionListener-Listens to the list of active sessions in a web application.

Httpservlet class.

Cookie- creates a cookie.

HttpServlet- Provides an abstract class to create an HTTP servlet suitable for a Web site.

HttpServletRequestWrapper- Provides a convenient implementation of the HttpServletRequest interface. It can be subclassed by developers who wish to adapt the request to a Servlet.

HttpServletResponseWrapper- Provides a convenient implementation of the HttpServletResponse interface. It can be subclassed by developers who wish to adapt the response from a Servlet.

HttpSession Binding Event- The events are sent to an object that implements HttpSessionBindingListener when it is bound or unbound from a session.

HttpSessionEvent- This class represents event notifications for changes to sessions within a web application.

HttpServlet Methods:

The abstract class for creating servlets is httpservlets.It provides the framework for handling the http protocol. Since it is an abstract class, the servelet writer must override at least one method. The overridden methods are

  • doGet -if the servlet supports HTTP GET requests , we can use this method.
  • doPost- It is used for HTTP POST requests
  • doPut- It is used for HTTP PUT requests
  • doDelete-It is used forHTTP DELETE requests
  • init and destroy- it is usedto manage resources that are held for the life of the servlet.
  • getServletInfo – It is used bythe servlet to provide information about itself.

Constructor

public HttpServlet() – This is an abstract class.

Methods:

  1. protected void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, java.io.IOException

This method is called by the server to allow a servlet to handle a GET request.

  1. Protected long getLastModified(HttpServletRequest req)

This method returns the time the HttpServletRequest object was last modified.

  1. protected void doHead(HttpServletRequest req, HttpServletResponse resp) throws ServletException,java.io.IOException

This method receives an HTTP HEAD request from the protected service method and handles the request.

  1. protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, java.io.IOException

This method is called by the server to allow a servlet to handle a POST request.

  1. protected void doPut(HttpServletRequest req,HttpServletResponse resp)throws ServletException, java.io.IOException

This method is called by the server  to allow a servlet to handle a PUT request.

  1. protected void doDelete(HttpServletRequest req,HttpServletResponse resp) throws ServletException, java.io.IOException

This method is called by the server  to allow a servlet to handle a DELETE request.

  1. protected void service(HttpServletRequest req,HttpServletResponse resp) throws ServletException, java.io.IOException

This method receives standard HTTP requests from the public service method.

HttpServletRequest interface extends the ServletRequest interface to provide request information for HTTP servlets. The servlet container creates an HttpServletRequest object and passes it as an argument to the servlet's service methods (doGet, doPost, etc).

Methods of HttpServletRequest:

  1. public abstract String getAuthType() – It gets the authentication of this request.
  2. public abstract Cookie[] getCookies() – it gets the array of cookies found in the request.
  3. public abstract String getHeader(String name)- It gets the requested header field.
  4. public abstract int getIntHeader(String name)- It gets the value of the specified integer header field of this request.
  5. public abstract String getMethod()- It gets the HTTP method such as Get,POST,PUT etc.
  6. public abstract String getPathInfo()- It gets an optional path information following the servlet path.
  7. public abstract String getQueryString()- It gets the query string which is part of the HTTP request.
  8. public abstract String getRequestedSessionId()- It gets the session id specified with the request.
  9. public abstract String getRequestURI() – It gets the first line of the HTTp request.
  10. public abstract String getServletPath()- It gets the path of the URI request which refers to the invoked servlet.
  11. public abstract HttpSession getSession(boolean create)- It gets the valid session associated with the request.

The servletresponse is extended from HttpServletResponse to provide HTTP specific functionality in sending a response.

 

Java Programming Assignment Help

Methods of HttpServletResponse:

  1. public abstract void addCookie(Cookie cookie)-  It adds the specified cookie to the response.
  2. public abstract boolean containsHeader(String name)- It checks whether the response message header has a field with specific name.
  3. public abstract void sendError(int sc, String msg) throws IOException- It sends an error response to the client using the specified status code.
  4. public abstract void sendRedirect(String location) throws IOException – It sends a temporary redirect response to the client using the specified URL. The URL used must be absolute.
  5. public abstract void setDateHeader(String name, long date)-A field is added to the response header with the specified name and date-valued field.
  6. public abstract void setHeader(String name, String value)- It adds a field to the respose header with specified name and value.
  7. public abstract void setStatus(int sc)- It sets thye status code for this respose.

There are two common ways to pass a data from the web browser to the web server. They are called POST and GET. The  'key=value' format is used to pass the data’s. The general syntax is given below:

POST" >

        ...Input

        ...Input elements go here...

Using the GET method

When the submit button is clicked , the browser will execute the following url.

http://www.aswp.com/servlets/sauaservlet?thisIsAKey=ZZZZ&nextkey=XXXX

The data is appended to the URL using ‘?’.

Using the POST Method

All of the data submitted by the user can not be displayed by the URl. Using the POSt method the data is passed to the web server separately from the URL in the hidden format.

Servlet methods to read the form data 

The servlets can read the data sent by the user the two methods of the HttpServletRequest interface.

 

String getParameter(String parameter-name)

String[]  getParameterValues(String parameter-name)

 String[] getParameterNames()

 

Example:

HTML File

Two Integers

 

ENTER TWO NUMBERS

First Number:  
Second Number:  

Program:

 

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class Add extends HttpServlet

{

public void doGet(HttpServletRequest request,

HttpServletResponse response)throws ServletException, IOException

{

int a,b,s;

a=Integer.parseInt(request.getParameter("p1"));

b=Integer.parseInt(request.getParameter("p2"));

s=a+b;

response.setContentType("text/html");

PrintWriter out = response.getWriter();

String title = "Adding two numbers";

out.println(" \n"+            "\n" +

"" + title + "\n" +

"\n" +

" Number 1: " + a + "\n" +

" Number 2: " +b + "\n" +

"Sum       :"+s+"\n"+

"\n" +

"");

}

}

The Meta data sent with HTTP request are called as headers. It consists of one or more response headers. Cookies are specified using the response headers. It is used to supply the modification date which is used to instruct the browser to reload the page after designated interval.

 

HTTP/1.1 200 OK
Content-Type: text/html
Header2: ...
...
HeaderN: ...
(Blank Line)

...

...

Setting Headers

void addHeader(String name, String value)

void setHeader(String name, String value)

The common headers can be specified in the following way

setContentType :It sets the Content-Type header.

setContentLength :ItSets the Content-Length header Used for persistent HTTP connections.

addCookie :It Adds a value to the Set-Cookie header.

sendRedirect :It Sets the Location header.

 

Common HTTP 1.1 Response Headers

Content-Disposition – It allows to request that the browser will ask the user to save the response to a file.

Content-Disposition: attachment; filename=file-name

Content-Encoding – It describes the way document is encoded.

Content-Length – It describes thenumber of bytes in the response.

Content-Type – It describesthe MIME type of the document being returned.

Expires – It describes the documents out-of time date.

Last-Modified – It describe the time when the document was last changed.

Location –It describes the URL to which browser should reconnect.

Set-Cookie – It describe the cookies that browser should remember

 

HTML

<HTML>

<HEAD>

<TITLE>                Example  TITLE>

HEAD>

<BODY>

<CENTER>

<FORM ACTION="/servlet/redirection">

Select the website <BR> <BR>

<SELECT NAME="webs">

<OPTION VALUE="rediff">Java OPTION>

<OPTION VALUE="Google">Google OPTION>

SELECT> <BR> <BR>

<INPUT TYPE="SUBMIT" VALUE="Browse">

<FORM>

CENTER>

BODY>

<HTML>

 

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class redirection extends HttpServlet

{

public void doGet(HttpServletRequest request,

HttpServletResponse response)throws ServletException, IOException

{

if (request.getParameter("webs").equals("Rediff"))

response.sendRedirect("http://www.Rediff.com");

else

response.sendRedirect("http://www.google.com");

}

}

 

Html program to read user information

Cookies

Create a cookie to send to your browser

Login Form

User Name:  
Password:  
 

Servlet program to set cookie

import java.io.*;

import javax.servlet.http.*;

import javax.servlet.ServletException;

public class set extends HttpServlet

{

public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException

{

response.setContentType("text/html");

PrintWriter out = response.getWriter();

String name = request.getParameter("user");

String value=request.getParameter("pass");

Cookie ck = new Cookie(name,value);

response.addCookie(ck);

out.println("Cookie has set "); 

 

                                out.println("

"); 

 

 

out.println(""+"

");

 

 

}

 

}

 

 

 

Servlet Program to read the Cookie*-

 

import java.io.IOException;

 

import java.io.PrintWriter;

 

import javax.servlet.ServletException;

import javax.servlet.http.*;

publicclass get extends HttpServlet

{

publicvoid doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException

{

Cookie[] co = request.getCookies();

response.setContentType("text/html");

PrintWriter out= response.getWriter();

out.println("");

out.print("

");

for(int i =0; i < co.length; i++)

&nbs

username Secret Code