Structure Query Language, C programming, Java, Servlet, Jsp, Unix

Tuesday 14 February 2012

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).

HTML FILE : 

<html>
<body>
<h2><marquee behavior="alternate" speed="2"> GTU MCA SYLLABUS LIST </marquee></h2>
<form action="showpdf.com" method="GET">
<table border=1>
<tr>
<td>
Your Name : 
<td>
<input type="text" name="name">
<tr>
<td>
Select Pdf :
<td>
<select name="sem">
<option value="1">MCA Sem - 1</option>
<option value="2">MCA Sem - 2</option>
<option value="3">MCA Sem - 3</option>
</select>
<tr>
<td colspan=2 align="center">
<input type="submit" value="SHOW">
</table>
</form>
</body>
</html>


SERVLET CLASS : 

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class pro15 extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
res.setContentType("application/pdf");
PrintWriter out=res.getWriter();
String name=req.getParameter("sem")+".pdf";
res.sendRedirect(name);
}
}

3 comments:

  1. i have a existing pdf file in which i want to open a pdf file by using a servlet code.
    My question is where i put a pdf file?
    Can i put pdf file in (classes) folder which is to be lie in the WEB-INF?

    ReplyDelete
  2. out side of WEB-INF file and pdf file name should be 1.pdf , 2.pdf , 3.pdf

    ReplyDelete