-
Jan 17th, 2006, 01:29 AM
#1
Rookie Question about View
Hi,
I need to manage a lot of pdf documents in my system.
Can i just do something like this?
<bean id="pdfViewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
<property name="prefix" value="/WEB-INF/templates/"/>
<property name="suffix" value=".pdf"/>
</bean>
so when my action controller received the request by document id like doc901, I just return "new ModelAndView("doc901")"
a pdf document at /WEB-INF/templates/doc901.pdf should be displayed to the user.
I have tried this, but it fails to display the pdf document.
Anyone can help me.
thanks,
victor
-
Jan 17th, 2006, 06:53 AM
#2
Why don't you simply put the .pdf in some directory on your webapp's root and let it be served by your appserver?
http://yourhost:8080/contextroot/pdf/doc901.pdf
No need to configure anything.
-
Jan 17th, 2006, 12:00 PM
#3
Do you want to open a link or do you want to stream the pdf to the client? It might be nessary to change the header. Have a look at the abstract pdf view.
-
Jan 17th, 2006, 09:32 PM
#4
hi,
for secuity reason, i need to put all pdf documents under WEB-INF folder, (I will verify user's privilege first) how can i put a direct link under this situation?
anyone can help me?
thanks
victor
-
Jan 17th, 2006, 09:42 PM
#5
To return a PDF to a browser I simply use the AbstractPdfView Class
There's a example in the countries example included in the distribution.
You should try to have a look
here's a very simple example :
my controller:
public class Send2Page implements Controller {
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
return new ModelAndView(new HelloPdfView());
}
}
Here's the abstractPdfView
public class HelloPdfView extends AbstractPdfView {
protected void buildPdfDocument(Map model, Document document, PdfWriter writer,
HttpServletRequest request, HttpServletResponse response)
throws DocumentException, NoSuchMessageException {
document.add(new Paragraph("Hello World"));
document.add(new Paragraph("Salut, hello in french"));
Paragraph paragraph = new Paragraph();
paragraph.add("je suis vraiment hot");
paragraph.add("Sans Modestis
");
paragraph.add("une cellule ca fait quoi?");
document.add(paragraph);
}
}
And the config
web.xml
<servlet-mapping>
<servlet-name>springapp</servlet-name>
<url-pattern>*.pdf</url-pattern>
</servlet-mapping>
springapp-servlet.xml
<!--you will need you create a beanNameUrlHanlderMapping, if you are not
creating a SimpleUrlHandlerMapping-->
<bean id="defaultHandlerMapping" class="org.springframework.web.servlet.handler.Bea nNameUrlHandlerMapping"/>
<bean name="/showme.pdf" class="web.Send2Page">
</bean>
good luck man
Now I'm trying to open the pdf in a new window(new browser), so the user
don't have to click back in order to get back to application.
Do you where I can find the information?
-
Jan 17th, 2006, 10:05 PM
#6
hi,
i have static pdf documents created already (all are located under /WEB-INF/templates/pdf/). what i need to do is to collect pdf name from user, then return the specified pdf document to the user.
thanks
victor
-
Jan 17th, 2006, 10:28 PM
#7
You understand your need now,
I don't know how to do it, but I guess will be to
render the pdf that user asked in a AbstractView and
then return it in a controller.
You should take a look at the class abstractPdfView and
AbstractView.
try to look a the source that comes with spring
try to look at how the people of Spring did extend AbstractPdfView
from AbstractView.
Also I remember that when I did that kinda stuff in the old fashion
way (servlet) I need to use
that line of command
response.setContentType("application/pdf");
read a pdf file,
and write it to the output stream (response.getOutputStream()
can't find example right now. sorry
But my advice before returning to the servlet mode,
try to a have a peek on the spring code. It comes with the
distribution, lot's a interesting stuff in.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules