Search This Blog
Showing posts with label servlet and jsp. Show all posts
Showing posts with label servlet and jsp. Show all posts
Tuesday, 10 June 2014
Thursday, 9 January 2014
how to write data into PDF using Servlet
Example to write data into PDF using servlet
Let's see the simple example of writing data into PDF using servlet. In this example, we have mentioned the content type application/pdf that must be specified to display data in the PDF format.
ServletPDF.java- package com.javatpoint;
- import java.io.*;
- import java.util.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
- import com.darwinsys.spdf.PDF;
- import com.darwinsys.spdf.Page;
- import com.darwinsys.spdf.Text;
- import com.darwinsys.spdf.MoveTo;
- public class ServletPDF extends HttpServlet {
- public void doGet(HttpServletRequest request,
- HttpServletResponse response) throws IOException {
- PrintWriter out = response.getWriter();
- response.setContentType("application/pdf");
- response.setHeader("Content-disposition","inline; filename='rajvishwakarma15@blogspot.pdf'");
- PDF p = new PDF(out);
- Page p1 = new Page(p);
- p1.add(new MoveTo(p, 200, 700));
- p1.add(new Text(p, "rajvishwakarma15@blogspot.com"));
- p1.add(new Text(p, "by Raj Vishwakarma"));
- p.add(p1);
- p.setAuthor("Ian ");
- p.writePDF();
- }
- }
download this example (developed using Myeclipse IDE)
download this example (developed using Eclipse IDE)
download this example (developed using Netbeans IDE)
download this example (developed using Eclipse IDE)
download this example (developed using Netbeans IDE)
Ref. javatpoint.com
Expression Language (EL) in JSP
Expression Language (EL) in JSP
There are many implicit objects, operators and reserve words in EL.The Expression Language (EL) simplifies the accessibility of data stored in the Java Bean component, and other objects like request, session, application etc.
It is the newly added feature in JSP technology version 2.0.
EL helps you to save your programming time.
Syntax for Expression Language (EL)
Implicit Objects in Expression Language (EL)
| There are many implicit objects in the Expression Language. They are as follows: |
| Implicit Objects | Usage |
|---|---|
| pageScope | it maps the given attribute name with the value set in the page scope |
| requestScope | it maps the given attribute name with the value set in the request scope |
| sessionScope | it maps the given attribute name with the value set in the session scope |
| applicationScope | it maps the given attribute name with the value set in the application scope |
| param | it maps the request parameter to the single value |
| paramValues | it maps the request parameter to an array of values |
| header | it maps the request header name to the single value |
| headerValues | it maps the request header name to an array of values |
| cookie | it maps the given cookie name to the cookie value |
| initParam | it maps the initialization parameter |
| pageContext | it provides access to many objects request, session etc. |
Simple example of Expression Language that prints the name of the user
| In this example, we have created two files index.jsp and process.jsp. The index.jsp file gets input from the user and sends the request to the process.jsp which in turn prints the name of the user using EL. |
index.jsp
process.jsp
Example of Expression Language that prints the value set in the session scope
| In this example, we printing the data stored in the session scope using EL. For this purpose, we have used sessionScope object. |
index.jsp
process.jsp
Example of Downloading file from the server using JSP
Example of Downloading file from the server using JSP
| In this example, we are going to download the jsp file. But you may download any file. For downloading the file from the server, you should specify the content type named APPLICATION/OCTET-STREAM. |
index.jsp
| This file provides a link to download the jsp file. |
download.jsp
| In this example, we are downloading the file home.jsp which is located in the e: drive. You may change this location accordingly. |
- <%
- String filename = "home.jsp";
- String filepath = "e:\\";
- response.setContentType("APPLICATION/OCTET-STREAM");
- response.setHeader("Content-Disposition","attachment; filename=\"" + filename + "\"");
- java.io.FileInputStream fileInputStream=new java.io.FileInputStream(filepath + filename);
- int i;
- while ((i=fileInputStream.read()) != -1) {
- out.write(i);
- }
- fileInputStream.close();
- %>
Ref. Javatpoint.com
Subscribe to:
Posts (Atom)