Saturday 22 June 2013

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

WTAD Practical - 15
Write a Servlet to display parameters available on request.
index.html


<HTML>
<HEAD>
<TITLE>WTAD.practical-15 @iAmLearningHere </TITLE>
</HEAD>
<BODY bgcolor="YellowGreen">
<h3>DISPLAY Syllabus in pdf</h3>
<hr>
<form name="f1" action="display" method="get" >
MCA-1<br>
MCA-2<br>
MCA-3<br>
<input type="text" name="MCA" value="" />
<input type="submit" value="Show Syllabus" />
</form>
</BODY>
</HTML>


WEB-INF/web.xml
<web-app>
<servlet>
<servlet-name>s15</servlet-name>
<servlet-class>Syllabus</servlet-class>
</servlet>
<!-- Servlet Mapping -->
<servlet-mapping>
<servlet-name>s15</servlet-name>
<url-pattern>/display</url-pattern>
</servlet-mapping>
</web-app>


WEB-INF/classes/Syllabus.java


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

public class Syllabus extends HttpServlet
{
private int count = 0;
public void doGet( HttpServletRequest request,HttpServletResponse response ) throws ServletException,IOException
{
// set contenttpe as pdf
response.setContentType("application/pdf");
PrintWriter out=response.getWriter();

String semester = request.getParameter("MCA");
response.sendRedirect(semester + ".pdf");


}
}

Preview



How to Run?
> Start Apache Server
> Put 3 pdf file named MCA-1, MCA-2, MCA-3
> Start localhost and open program folder
> Enter File name and submit

For all WTAD programs wtad-pra cticals.html
To get all programs in your inbox.Enter your email

Kindly Bookmark and Share it:

1 comments :

Unknown on Wednesday, April 04, 2018 12:27:00 pm said...

hello, today as always your post is lovely that I liked it and I am waiting for your new works in future, good luck to all of you.
digital marketing services in delhi

Post a Comment

Any Query ? any suggestion ? comment here

 

Recent Post

Recent Comments

© 2010 IamLearningHere Template by MBT