我有一个域类
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
}
我需要做的是,我的视图页面中有三个下拉列表,当我选择其中的 3 个并单击下载链接时,需要下载已上传到数据库中的特定 pdf。
当我运行我的代码时,我没有收到任何错误,而是收到“页面变得无响应。请终止或等待浏览器。”