Program
save with Name: index.html
<html>
<head><title>Downloading
Program</title></head>
<body>
<a
href="wordServlet">Ms-Word-Document</a><br>
<a
href="excelServlet">Ms-Excel-Document</a>
</body>
</html>
|
Program
save with Name: 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("This
document is dynamically generated by the servlet");
out.println("Its
purpose to demostrate the use of content type.");
out.close();
}
}
|
Program
save with Name: ExcelServlet.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-excel");
PrintWriter
out=response.getWriter();
out.println("Name\t
Job\t Salary");
out.println("Aman\t
Trainer\t 5000");
out.println("Deepak\t
Excutive\t 5000");
out.println("Rahul\t
Mnage\t 5000");
out.println("\t
Total Salary\t=sum(c2:c4)");
out.close();
}
}
|
Program
save with Name: web.xml
<web-app>
<servlet>
<servlet-name>s1</servlet-name>
<servlet-class>WordServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s1</servlet-name>
<url-pattern>wordServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>s2</servlet-name>
<servlet-class>ExcelServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s2</servlet-name>
<url-pattern>excelServlet</url-pattern>
</servlet-mapping>
</web-app>
|
Output :
Click on Hyperlink to access or download
word and excel document.
|
Sunday, December 24, 2017
Program to access word and Excel document (Demonstrate the use of ServletRequest and ServletResponse methods such as setContentType())
Subscribe to:
Post Comments (Atom)
Java Functional Interface
Java Lambda expression Lambda expression came to enable to use functional programming feature in java. It provides the facility t...

-
The ObjectAid UML Explorer for Eclipse The ObjectAid UML Explorer is an agile and lightweight code visualization tool for the Eclipse ...
-
Adapter Design Patterns provides an interface between two unrelated entities so that they can work together. One of the great real lif...
-
Create Table with following field: TableName: USERINFO id name password 101...
No comments:
Post a Comment