Catfish
Catfish

Reputation: 19314

pass data to a servlet

Basically we have a JSF app that dynamically generates a link to a servlet, which serves up the PDF file. I need to pass the path of the PDF to the servlet. I have no idea of how to pass data to a servlet.

In the View we have:

<d:protocolSection value="#{detailBacker.studyData}" id="protocol" />

In the controller we have

public string getFile() {
  .......
  // some variable here that holds the folder and file name
  result += "<a href=\"/catalog/catalog/WelcomeServlet\"  target=\"_blank\">" + name + "</a>
  .......
}

I basically need to send the variable that holds the folder and file name to the WelcomeServlet somehow so that the WelcomeServlet can use it.

Upvotes: 1

Views: 1365

Answers (2)

Jigar Joshi
Jigar Joshi

Reputation: 240966

keep the location fixed of generated/created pdf files and just pass the name of file like

/pdfServlet?fileName=#{someBean.someFileName}

in servlet's doGet() retrieve the fileName and serve the file.

String fileName = request.getParameter("fileName");

Upvotes: 0

BalusC
BalusC

Reputation: 1109570

Pass it as a request parameter or pathinfo the usual Servlet way.

Here's an example assuming pathinfo is preferred and #{bean.pdfpath} returns something like filename.pdf:

<h:outputLink value="pdf/#{bean.pdfpath}">Download pdf</h:outputLink>

In the servlet mapped on an URL pattern of /pdf/* you can get it as follows in doGet() method:

String pdfpath = request.getPathInfo();
// ...

As a completely different alternative, you can also just let JSF write the PDF to the response in a commandlink/commandbutton action method.

Upvotes: 2

Related Questions