我想从我的 Web 应用程序中打开一个文件。
我有一个jsp,在这段代码中,当我单击它应该打开一个文件的按钮时,我的代码jsp(特别是javascript代码)调用java代码但我有一个错误:Null-pointer Exception
我认为这个错误通常是因为我将变量response
设为null
,但我不知道何时应该填写response
( HttpServletResponse response
)
我的JSP代码如下:
<div id="pieces" class="baliseDiv">
<fieldset style="padding: 5px 10px 5px 10px;">
<legend align="top">
<util:message key="operateur.section.pieces.title" />
</legend>
<grid:view name="PieceRattacheList_view">
<grid:search position="top" align="right" width="200"
iconClass="icon-zoom" />
<grid:actionsbar>
<grid:action id="pieceRattacheList_add" type="button"
textkey="operateur.list.pieceRattacheList.action.pieceRattacheList_add.title"
tooltipkey="operateur.list.pieceRattacheList.action.pieceRattacheList_add.description"
iconClass="icon-form-add" onclick="action_pieceRattacheList_add" />
<grid:action id="pieceRattacheList_add_Split" type="splitbar" />
</grid:actionsbar>
<grid:pagingbar pageSize="10" displayInfo="true">
</grid:pagingbar>
<grid:table name="PieceRattacheList_Tab" list="pieceRattacheList"
titlekey="operateur.list.pieceRattacheList.title"
formbean="DossierJuridiquePortletBean" recordForm="false"
clicksToEdit="1" collapsible="true" closable="true" render="true">
<grid:repository id="pieceRattacheList.pieceRattacheList"
classpath="com.dq.foprodex.web.repository.DossierJuridiqueRepository" />
<grid:record id="attachementEntity" idProperty="id"
defaultSortColumn="nomfrPiece" defaultSortDir="ASC"
title="Enregistrement" columnCount="2"
iconClass="icon-edit-record"
recordClass="com.dq.foprodex.web.entity.AttachementEntity"
windowmodal="false">
<grid:property name="id" type="String" />
<grid:property name="idElement" type="String" />
<grid:property name="idTable" type="String" />
<grid:property name="idGuid" type="String" />
<grid:property name="nomfrPiece" type="String" />
<grid:property name="nomarPiece" type="String" />
<grid:property name="etat" type="String" />
<grid:property name="fo" type="String" />
<grid:property name="df" type="String" />
<grid:property name="agBack" type="String" />
<grid:property name="respBack" type="String" />
<grid:property name="pdg" type="String" />
<grid:property name="idType" type="String" />
<grid:property name="libType" type="String" />
<grid:property name="respRattach" type="String" />
<grid:property name="dateRattach" type="String" />
<grid:property name="nbreRappel" type="Integer" />
<grid:property name="dateDernRappel" type="String" />
<grid:property name="dateDemComp" type="String" />
<grid:property name="dateDepotComp" type="String" />
<grid:property name="idAvis" type="String" />
<grid:property name="libAvis" type="String" />
<grid:property name="comm" type="String" />
<grid:property name="app" type="String" />
<grid:property name="dateApp" type="String" />
<grid:property name="avisColumn" type="String" />
<grid:property name="motif" type="String" />
<grid:property name="rattachement" type="String" />
<grid:property name="actiondocumentdiffuser" type="String" />
<grid:property name="form" />
</grid:record>
<grid:column property="nomfrPiece"
titlekey="operateur.list.pieceRattacheList.column.nomfrPiece.title"
sortable="true" resizable="true" menuDisabled="false" width="20">
</grid:column>
<grid:column property="rattachement"
titlekey="operateur.list.pieceRattacheList.column.rattachement.title"
sortable="true" resizable="true" menuDisabled="false" width="40">
</grid:column>
<grid:column property="respRattach"
titlekey="operateur.list.pieceRattacheList.column.respRattach.title"
sortable="true" resizable="true" menuDisabled="false" width="40">
</grid:column>
<grid:column property="dateRattach"
titlekey="operateur.list.pieceRattacheList.column.dateRattach.title"
sortable="true" resizable="true" menuDisabled="false" width="40">
</grid:column>
<grid:column property="nbreRappel"
titlekey="operateur.list.pieceRattacheList.column.nbreRappel.title"
sortable="true" resizable="true" menuDisabled="false" width="40">
</grid:column>
<grid:column property="dateDernRappel"
titlekey="operateur.list.pieceRattacheList.column.dateDernRappel.title"
sortable="true" resizable="true" menuDisabled="false" width="40">
</grid:column>
<grid:column property="etat"
titlekey="operateur.list.pieceRattacheList.column.etat.title"
sortable="true" resizable="true" menuDisabled="false" width="40">
</grid:column>
<grid:column property="comm"
titlekey="operateur.list.pieceRattacheList.column.comm.title"
sortable="true" resizable="true" menuDisabled="false" width="40">
</grid:column>
<grid:column property="rowaction2" width="5">
<grid:rowaction id="piece"
tooltipkey="operateur.list.pieceRattacheList.action.pieceRattacheList_update1.title"
iconClass="icon-form-key1"
onclick="action_consultDoc"/>
</grid:column>
</grid:table>
</grid:view>
<br>
</fieldset>
</div>
<script type="text/javascript">
function action_consultDoc(grid, record, row, col) {
operateurService.consultDocService(Ext.getCmp('userId').getValue(),record.get('id'), {
callback : function(responseEntity) {
}
});
}
</script>
consultDocService
该类的方法operateurService
是:
public void consultDocService(String userid, String id) {
DossierJuridiqueManager dossierJuridiqueManager =
(DossierJuridiqueManager) PortalUtil.getBean(DossierJuridiqueManager.managerid);
try {
dossierJuridiqueManager.consultDoc(null, null, userid, id);
} catch (Exception e) {
e.printStackTrace();
}
}
consultDoc
我班的代码DossierJuridiqueManager
:
public ResponseEntity consultDoc(HttpServletRequest request, HttpServletResponse response, String userid, String id)
throws Exception {
System.out.println("the ids"+id);
List<AttachementEntity> attachements = attachementDAO.getAttachementList(id);
AttachementEntity attachementEntity=new AttachementEntity();
attachementEntity=attachements.get(0);
String guid=attachementEntity.getIdGuid();
P8Connector connector = new P8Connector(TypeEnum.CE.value(), "gcd admin","C:/properties/");
System.out.println("verif " + connector.getConnection());
GetDocumentsListInFolder getDocumentsListInFolder = new GetDocumentsListInFolder();
List<Document> list = new ArrayList<Document>();
list = getDocumentsListInFolder.execute(connector, "/chemin", "1");
int length = 0;
ServletOutputStream op = response.getOutputStream();
for (int i = 0; i < list.size(); i++) {
Document doc = (Document) list.get(i);
String h = doc.get_Id().toString();
if(h.equals(guid))
{
GetDocumentContent c = new GetDocumentContent();
byte[] is1 = c.execute(connector, doc);
byte[] bbuf = new byte[1024];
InputStream is3 = new ByteArrayInputStream(is1);
DataInputStream in = new DataInputStream(is3);
while ((in != null) && ((length = in.read(bbuf)) != -1)) {
op.write(bbuf, 0, length);
}
in.close();
op.flush();
op.close();
}
}
return new ResponseEntity();
}
该错误NullPointerException
与此行有关:
ServletOutputStream op = response.getOutputStream();
这是因为我通过这段代码做到response
了:null
dossierJuridiqueManager.consultDoc(null,null, userid, id);
但是我应该什么时候填写response
?