我試圖使用不同的方法保存.pdf文件,我發現在stackoverflow上,包括FileUtils IO
,但是,我總是會損壞它。當我用記事本打開損壞的文件,我得到了以下的東西:如何從瀏覽器保存.pdf?
<HEAD>
<TITLE>
09010b129fasdf558a-
</TITLE>
</HEAD>
<HTML>
<SCRIPT language="javascript" src="./js/windowClose.js"></SCRIPT>
<LINK href="./theme/default.css" rel="stylesheet" type="text/css">
<LINK href="./theme/additions.css" rel="stylesheet" type="text/css">
<BODY leftmargin="0" topmargin="0">
<TABLE cellpadding="0" cellspacing="0" width="100%">
<TR>
<TD class="mainSectionHeader">
<A href="javascript:windowClose()" class="allLinks">
CLOSE
</A>
</TD>
</TR>
</TABLE>
<script language='javaScript'>
alert('Session timed out. Please login again.\n');
window.close();
</script>
</BODY>
</HTML>
後來,我試着從使用@BalusC提供的答案瀏覽器保存.pdf
文件。此解決方案非常有用:我能夠擺脫session
問題。但是,它也會產生一個損壞的.pdf。但是當我用記事本打開它時,情況完全不同。沒有登錄問題了,但:
<HTML>
<HEAD>
<TITLE>
Evidence System
</TITLE>
</HEAD>
<LINK href="./theme/default.css" rel="stylesheet" type="text/css">
<TABLE cellpadding="0" cellspacing="0" class="tableWidth760" align="center">
<TR>
<TD class="headerTextCtr">
Evidence System
</TD>
</TR>
<TR>
<TD colspan="2">
<HR size="1" noshade>
</TD>
</TR>
<TR>
<TD colspan="2">
<HTML>
<HEAD>
<link href="./theme/default.css" rel="stylesheet" type="text/css">
<script language="JavaScript">
function trim(str)
{
var trmd_str
if(str != "")
{
trmd_str = str.replace(/\s*/, "")
if (trmd_str != ""){
trmd_str = trmd_str.replace(/\s*$/, "")
}
}else{
trmd_str = str
}
return trmd_str
}
function validate(frm){
//check for User name
var msg="";
if(trim(frm.userName.value)==""){
msg += "Please enter your user id.\n";
frm.userName.focus();
}
if(trim(frm.password.value)==""){
msg += "Please enter your password.\n";
frm.userName.focus();
}
if (trim(msg)==""){
frm.submit();
}else{
alert(msg);
}
}
function numCheck(event,frm){
if(event.keyCode == 13){
validate(frm);
}
}
</script>
</HEAD>
<BODY onLoad="document.frmLogin.userName.focus();">
<FORM name='frmLogin' method='post' action='./ServletVerify'>
<TABLE width="100%" cellspacing="20">
<tr>
<td class="mainTextRt">
Username
<input type="text" name="userName" maxlength="32" tabindex="1" value=""
onKeyPress="numCheck(event,this.form)" class="formTextField120">
</TD>
<td class="mainTextLt">
Password
<input type="password" name="password" maxlength="32" tabindex="2" value=""
onKeyPress="numCheck(event,this.form)" class="formTextField120">
</TD>
</TR>
<tr>
<td colspan="2" class="mainTextCtr" style="color:red">
Unknown Error
</td>
</tr>
<tr>
<td colspan="2" class="mainTextCtr">
<input type="button" tabindex="3" value="Submit" onclick="validate(this.form)" >
</TD>
</TR>
</TABLE>
<INPUT TYPE="hidden" NAME="actionFlag" VALUE="inbox">
</FORM>
</BODY>
</HTML>
</TD>
</TR>
<TR>
<TD height="2"></TD>
</TR>
<TR>
<TD colspan="2">
<HR size="1" noshade>
</TD>
</TR>
<TR>
<TD colspan="2">
<LINK href="./theme/default.css" rel="stylesheet" type="text/css">
<TABLE width="80%" align="center" cellspacing="0" cellpadding="0">
<TR>
<TD class="footerSubtext">
Evidence Management System
</TD>
</TR>
<!-- For development builds, change the date accordingly when sending EAR files out to Wal-Mart -->
<TR>
<TD class="footerSubtext">
Build: v3.1
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</HTML>
我有什麼其他選擇?
PS:當我嘗試使用CTRL+Shift+S
手動保存文件時,文件被保存成OK。
編輯我的回答Buras ..我認爲問題可能是位置。它試圖保存一個html文件而不是pdf。請參閱**編輯**部分,該部分將解釋「這不是二進制文件」以及讀者認爲它「已損壞」 – sircapsalot