Adv Java - [Servlet: Hyperlink Example]

♠ Posted by Unknown in at 06:34
Servlet Example

The Example that display the use of hyperlinks among several servlets. The Servlets are called to each other by referencing the java class name to the anchor element of HTML.


Write a Servlet program to display information regarding MCA-I, MCA-II, MCA-III using different links.

                                                        Mainpage.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>
            <CENTER>
            <H1>Computer Department, Patan</H1>
            <H2>MCA SYLLABUS INFORMATION</H2>
            </CENTER>
           
            <A HREF = "http://localhost:8080/servlet/McaFirst">
                        Mca 1st Semester
            </A>
            <BR>
            <A HREF = "http://localhost:8080/servlet/McaSecond">
                        Mca 2nd Semester
            </A>
</BODY>
</HTML>


                                                         McaFirst.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class McaFirst extends HttpServlet
{
            public void service(HttpServletRequest req, HttpServletResponse res) throws IOException
            {
                        res.setContentType("text/html");
                        PrintWriter out = res.getWriter();
                        out.print("<HEAD><TITLE>This is Example of MCA02</HEAD></TITLE>");
                        out.print("<BODY><CENTER><H1>COMPUTER DEPARTMENT, PATAN.</H1>");
                        out.print("<H2>INFORMATION OF MCA-01</H2></CENTER>");
                        out.print("<TABLE BORDER = 2>");
                        out.print("<TR><TH>SUBJECTS</TH> <TH>CREDITS</TH><TR>");
                        out.print("<TR><TD>C Language</TD> <TD>100</TD><TR>");
                        out.print("<TR><TD>Digital Electronics</TD> <TD>100</TD><TR>");
                        out.print("</TABLE></BODY>");
                        out.close();
            }
}

                                                        McaSecond.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class McaSecond extends HttpServlet
{
            public void service(HttpServletRequest req, HttpServletResponse res) throws IOException
            {
                        res.setContentType("text/html");
                        PrintWriter out = res.getWriter();
                        out.print("<HEAD><TITLE>This is Example of MCA02</HEAD></TITLE>");
                        out.print("<BODY><CENTER><H1>COMPUTER DEPARTMENT, PATAN.</H1>");
                        out.print("<H2>INFORMATION OF MCA-02</H2></CENTER>");
                        out.print("<TABLE BORDER = 2>");
                        out.print("<TR><TH>SUBJECTS</TH> <TH>CREDITS</TH><TR>");
                        out.print("<TR><TD>Visual Basic</TD> <TD>100</TD><TR>");
                        out.print("<TR><TD>Oracle</TD> <TD>100</TD><TR>");
                        out.print("</TABLE></BODY>");
                        out.close();
            }
}

0 comments:

Post a Comment