Servlets and JSP Assignment Help

Assignment Help: >> Servlets >> Servlets and JSP

Servlets and JSP:

It should be clear from the previous sections that servlets are very powerful - they have access to the full Java language for any processing required at the server in response to HTTP requests. However, much of the response to most requests is likely to consist of static elements defining the text, graphics and layout of the response web page. Writing these static elements to the output stream using a servlet is a rather awkward way to proceed. This can also make it harder to maintain such web pages and requires the attention of Java programmers rather than web page designers.

To address these problems, there is a very useful technology called Java Server Pages (usually known as JSP). A JSP is like a static page of HTML and text, but may also contain sections of Java code, indicated by special tags. If there is a lot of static HTML code in the response, it is worth using a JSP to construct the response page. The following code is the JSP required for the lucky numbers response page created using a servlet.

<HTML>
<HEAD>
<TITLE>Lucky Numbers</TITLE>
</HEAD>
<BODY>
<H1>Walrus Lottery</H1>
<BR> <BR>
<H2>Your lucky numbers are:</H2>
<BR> <BR>
<H1>
<%@ page import = "java.util. *" %>
<% Random random = new Random( );
for (int i = 0; i < 4; i++)
{
out.println(random.nextInt(MAX_VALUE) + 1);
}
%>
</H1>
<BR> <BR>
<H2>Wishing you the best of luck</H2>
<BR> <HR> <BR>
<H4>We do not guarantee a winning result</H4>
<H4>Walruses can go down as well as up</H4>
</BODY>
</HTML>

This is almost identical to the source of the page sent back by the servlet, except that the JSP contains the Java code needed to produce the dynamically generated part. The Java code section, known as a scriptlet, is enclosed in the special tags <% and %>. Note the slightly different, but recognizable, form of the import statement, which also uses special tags <%@ and %>.

In fact, when the JSP is processed, this simply creates an appropriate servlet to build the required response page. The JSP is stored in a normal text file, with a name ending in .jsp. A JSP can be directly accessed from a browser by entering its URL or clicking on a link, or it can be invoked by a servlet in constructing its response to a request. The method sendErrorReport could usefully be implemented to invoke a JSP with standard error reporting content together with dynamically generated information about the details of the error. The details of how servlets and JSPs communicate are outside the scope of this unit, but the principles should be clear.

To summarize:

  • if an HTTP response requires mostly HTML and a little bit of processing, use a JSP;
  • if an HTTP response requires mostly processing and a little static HTML, use a servlet;
  • often a good approach is to use both servlets and JSP, applying the strengths of each approach, and separating the processing from the user interface details.

 

Java Assignment Help - Java Homework Help

Struggling with java programming language? Are you not finding solution for your Servlets and JSP homework and assignments? Live Servlets and JSP experts are working for students by solving their doubts & questions during their course studies and training program. We at Expertsmind.com offer Servlets and JSP homework help, java assignment help and Servlets and JSP projects help anytime from anywhere for 24x7 hours. Computer science programming assignments help making life easy for students.

Why Expertsmind for assignment help

  1. Higher degree holder and experienced experts network
  2. Punctuality and responsibility of work
  3. Quality solution with 100% plagiarism free answers
  4. Time on Delivery
  5. Privacy of information and details
  6. Excellence in solving java programming language queries in excels and word format.
  7. Best tutoring assistance 24x7 hours

 

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd