-1

I am putting my code where I am facing problem.

WriteToPdf1.java

import java.io.*;
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 ServletPDF1 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='CreatePDFFile.pdf'");

        PDF p = new PDF(out);
        Page p1 = new Page(p);
        p1.add(new MoveTo(p, 200, 700));
        p1.add(new Text(p, "Hi This is created PDF file by using Servlet"));
        p1.add(new Text(p, "by us...Bhumesh Patel...."));

        p.add(p1);
        p.setAuthor("Bhumesh Patel....");

        p.writePDF();
    }
}

index.html

<a href="/servlet1">CLICK HERE</a> 

web.xml

    <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>WriteToPdf1</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>ServletPdf1</servlet-name>
    <servlet-class>ServletPdf1</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>ServletPdf1</servlet-name>
    <url-pattern>/servlet1</url-pattern>
  </servlet-mapping>
</web-app>

Please help I am doing this in eclipse jee mars and tried several options but could not execute it.I have attached all code. plz help.

Srana
  • 1
  • 1

1 Answers1

0

If you changed the url mapping of a servlet in your web.xml file during runtime of the server, (depending on your server) it will not pick up on the changes. Try cleaning, rebuilding and restarting the server.

Jonathan Laliberte
  • 2,672
  • 4
  • 19
  • 44
  • okay , what do you mean by rebuilding? – Srana Aug 26 '17 at 00:26
  • Each time you change something in your project, it usually builds automatically if your settings are set that way. If you're on Eclipse, click on the Project dropdown menu at the top of the window and you'll see "Build Automatically". Just restart your server and clean your project and you should see that the problem goes away. – Jonathan Laliberte Aug 26 '17 at 00:30
  • okay,.. but It still is not working. – Srana Aug 26 '17 at 01:09
  • I found a new error in error log "Warning: The environment variable HOME is not set. The following directory will be used to store the Git" – Srana Aug 26 '17 at 01:10
  • @Srana is your servlet in a package? Because maybe that's why it cannot be found. I normally keep my servlets in a package called 'servlets', so for the tag in web.xml, i write: servlets.ServletPdf1 – Jonathan Laliberte Aug 26 '17 at 01:22
  • no, I have not put it this way. I'll jus try this way. – Srana Aug 26 '17 at 03:51
  • sorry.. it dint work. - – Srana Aug 26 '17 at 07:22
  • It is done..thanks all – Srana Aug 31 '17 at 07:07