Java Servlet Programing Laungage

Java Servlet Projects

Servlet Project 3

adplus-dvertising
Java Servlet :Another example of Servlet
Previous Home Next

ExcelSevlet.java

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class ExcelServlet extends HttpServlet
	{
	public void doGet(HttpServletRequest request,
			HttpServletResponse response) 
			throws ServletException,IOException
	{
	response.setContentType("application/vnd.ms-exce");
	PrintWriter out=response.getWriter();
	out.println("Name\tCourse\tFee");
	out.println("Amit\tJava\t9000");
	out.println("Amit\tJava\t9000");
	out.println("Amit\tJava\t9000");
	out.println("\tTotal\t=Sum(C2:C4)");
	out.close();
	}
}

WordServlet.java

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

public class WordServlet extends HttpServlet
{
	public void doGet(HttpServletRequest request,HttpServletResponse response) 
			throws ServletException,IOException
	{
		response.setContentType("application/msword");
		PrintWriter out=response.getWriter();
		out.println("Name\tCourse\tFee");
		out.println("Amit\tJava\t9000");
		out.println("Amit\tJava\t9000");
		out.println("Amit\tJava\t9000");
		out.close();
	}
}

index.html

<html>
	<head>
		<title>FirstWeb application</title>
	</head>
	<body>
		<a href="wordFormat"> Word Format</a>
		<a href="excelFormat"> Excel Format</a>
	</body>
</html>

web.xml

<web-app>
	<servlet>
		<servlet-name>van</servlet-name>
		<servlet-class>WordServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>van</servlet-name>
		<url-pattern>wordFormat</url-pattern>
	</servlet-mapping>
	<servlet>
		<servlet-name>vani</servlet-name>
		<servlet-class>ExcelServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name> vani</servlet-name>
		<url-pattern>excelFormat</url-pattern>
	</servlet-mapping>
</web-app>
Previous Home Next