java - How to let user download a pdf file right after he visits a jsp page? -


simple question, i've got pdf generated on page load, subsequently want let user download file.

is there way it? show download dialog after pdf created?

i've tried this:

<%response.setheader("content-disposition", "attachment; filename=\""+filename+"\"");%> 

but define, file want user download? because code above leads user downloading corrupted empty pdf file.

i suggest servlet instead of jsp. have more control on code , less fragile (if handle response content in jsp , have single space or line feed between scriptlets, can written output stream corrupting file content).

so have @ fileservlet example , adapt needs.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -