我有一个域类
class UploadSyllabus {
String semester
Course course
Department department
byte[] uploadSyllabus
}
其中Course,Department是其他域类
在我的Show.gsp
页
<a style="margin-left: 108px;"href="javascript:getPdfFromDB()" id="downloadPdf">Download_Syllabus.pdf</a>
function getPdfFromDB(){
var formdata = $("#downloadSyllabusForm").serialize();
$.get("${grailsApplication.config.grails.serverURL}/uploadSyllabus/getPdfFromDBC", formdata, function(response) {
for (var i = 0; i < response.length; i++) {
document.getElementById("subjectResult").innerHTML=response
document.getElementById("courseResult").innerHTML=$("#course option:selected").text();
document.getElementById("semesterResult").innerHTML=$("#semester option:selected").text();
}
});
}
我的控制人员的行动:
def getPdfFromDBC = {
def sem = params.semester
def course = params.course
def department = params.department
List s= UploadSyllabus.executeQuery("select id from UploadSyllabus where department_id = "+params.department +"AND course_id = "+params.course + "AND semester = "+sem)
def product = UploadSyllabus.get(s[0])
println "product is ---"+product
response.contentType = 'application/pdf'
response.setHeader('Content-disposition', 'Attachment; filename=uploadSyllabus.pdf')
response.getOutputStream().write(product.uploadSyllabus)
response.getOutputStream().flush()
// render s.name as SHALLOW
}
我需要做的是我在视图页面中有三个下拉列表,当我选择其中三个并点击下载链接时,需要下载已在数据库中上传的特定pdf。
当我运行我的代码时,我没有收到任何错误,但得到“页面变得反应迟钝。请杀死或等待浏览器。”
答案 0 :(得分:0)
你不能在document.getElementById(“subjectResult”)中插入pdf。innerHTML = response
如果你想在html中渲染pdf,请使用pdf.js