GTU WTAD Practical 15 : Assume that we have got three pdf files for the MCA-1 Syllabus, MCA-2 Syllabus and MCA-3 Syllabus respectively, Now write a Servlet which displays the appropriate PDF file to the client, by looking at a request parameter for the year (1, 2 or 3)

GTU WTAD Practical 15 :  Assume that we have got three pdf files for the MCA-1 Syllabus, MCA-2 Syllabus and MCA-3 Syllabus respectively, Now write a Servlet which displays the appropriate PDF file to the client, by looking at a request parameter for the year (1, 2 or 3).

GTU WTAD Practical 15 : Assume that we have got three pdf files for the MCA-1 Syllabus, MCA-2 Syllabus and MCA-3 Syllabus respectively, Now write a Servlet which displays the appropriate PDF file to the client, by looking at a request parameter for the year (1, 2 or 3).

This Servlet program explains how to display PDF File as per the Request parameter sent by Page1. Here most important point is that Using servlet Program I am going to display PDF File. Copy 2 PDF File into gtu_15 folder(Save as 2640002.pdf and 2640012.pdf)  otherwise Servlet will gives you error.

Jump to GTU WTAD Practical 16

File Name : index.jsp

File Location : Tomcat_Apache\webapps\gtu_15\

<html>
	<head>
		<title>GTU WTAD Practical 15</title>
	</head>
	<body>
	
	<h2 align="center"> GTU WTAD Practical 15 :  Assume that we have got three pdf files for the MCA-1 Syllabus, MCA-2 Syllabus and MCA-3 Syllabus respectively, Now write a Servlet which displays the appropriate PDF file to the client, by looking at a request parameter for the year (1, 2 or 3). </h2>
	
	
	
		<table>
		<tr>
			<th>Select Subject Code to Download Syllabus </th>
		</tr>
		<tr>
		<td>
		<form action="/gtu15/GeneratePdf" method="get">
			<input type="radio" name="par1" value="2640002.pdf">2640002<br>
			<input type="radio" name="par1" value="2640012.pdf">2640012<br>
			<input type="submit" value="submit">
		</form>
		</td>
		</tr>
		</table>
	</body>
</html>

 

File Name : web.xml

File Location : Tomcat_Apache\webapps\gtu_15\WEB-INF

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  version="3.0"
  metadata-complete="true">  
  
  <display-name>GTU WTAD Practical 15  </display-name>
  <description>Assume that we have got three pdf files for the MCA-1 Syllabus, MCA-2 Syllabus and MCA-3 Syllabus respectively, Now write a Servlet which displays the appropriate PDF file to the client, by looking at a request parameter for the year (1, 2 or 3). </description>
  
  <servlet>
    <servlet-name>GeneratePdf</servlet-name>
    <servlet-class>GeneratePdf</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>GeneratePdf</servlet-name>
      <url-pattern>/GeneratePdf</url-pattern>
  </servlet-mapping> 
  
</web-app>

 

File Name : GeneratePdf.java

File Location : Tomcat_Apache\webapps\gtu_15\WEB-INF\classes

/*
		GTU WTAD Practical 15 :  Assume that we have got three pdf files for the MCA-1 Syllabus, MCA-2 Syllabus and MCA-3 Syllabus respectively, Now write a Servlet which displays the appropriate PDF file to the client, by looking at a request parameter for the year (1, 2 or 3). 
*/

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class GeneratePdf extends HttpServlet
{

	public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
	{
		response.setContentType("application/pdf");
		PrintWriter out = response.getWriter();
		String file=request.getParameter("par1");
		response.sendRedirect(file);
	}
}

 

 Output (index.jsp File)

GTU WTAD Practical 15 : Assume that we have got three pdf files for the MCA-1 Syllabus, MCA-2 Syllabus and MCA-3 Syllabus respectively, Now write a Servlet which displays the appropriate PDF file to the client, by looking at a request parameter for the year (1, 2 or 3).

 

Output of Servlet (GeneratePdf)

GTU WTAD Practical 15 : Assume that we have got three pdf files for the MCA-1 Syllabus, MCA-2 Syllabus and MCA-3 Syllabus respectively, Now write a Servlet which displays the appropriate PDF file to the client, by looking at a request parameter for the year (1, 2 or 3).

 

Leave a Reply