problems when using javascript in jsp

[nobr]hello, i am implementing a program to upload files.

a user can upload either a pdf or a latex file.

so for example if the user uploads a pdf file the form action should be

"uploadPDF.jsp" and if it is a latex file the action is "uploadlatex.jsp"

currently when the user uploads the pdf file IT WORKS and does the action correctly but it does not do it for the other file (latex file) gives

some long jasper exceptions pls help

*************here is the code*******************

<SCRIPT LANGUAGE="JavaScript">

var extArray = new Array(".pdf", ".tex", ".txt");

function LimitAttach(form, file) {

allowSubmit = false;

if (!file) return;

while (file.indexOf("\\") != -1)

file = file.slice(file.indexOf("\\") + 1);

ext = file.slice(file.indexOf(".")).toLowerCase();

for (var i = 0; i < extArray.length; i++) {

if (ext = "pdf"){

document.forms[0].action.value = "uploadPDF.jsp";

allowSubmit = true;

break;

}

}

if (allowSubmit) form.submit();

else

alert("Please only upload files that end in types: "

+ (extArray.join(" ")) + "\nPlease select a new "

+ "file to upload and submit again.");

}

</script>

</HEAD>

******************

and below is the form

******************

<form action="" name="upform"enctype="multipart/form-data">

<input type="file" name="PDFfilename" size="50">

<input type="hidden" name="todo" value="upload">

<input type="submit" name="Submit" value="Upload" onclick="LimitAttach(this.form, this.form.PDFfilename.value)">

</form>

**************************

thanks,

moh[/nobr]

[1794 byte] By [moh_1_and_onlya] at [2007-11-26 18:43:55]
# 1
post the exception stack trace...
ganesh_renganathana at 2007-7-9 6:17:50 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

when uploading this latex file in a different jsp file and form it works fine

however in the above form it does not...........here is the exception errors:

****************************************************

org.apache.jasper.JasperException: This file appears to be damaged and cannot be repaired. This may not actually be a PDF file.

org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)

com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)

com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)

com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)

com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)

com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)

javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)

org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)

root cause

javax.servlet.ServletException: This file appears to be damaged and cannot be repaired. This may not actually be a PDF file.

org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)

org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)

org.apache.jsp.uploadPDF_jsp._jspService(uploadPDF_jsp.java:209)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)

com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)

com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)

com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)

com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)

com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)

javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)

org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)

root cause

com.adobe.acrobat.pdfobjstore.CantRebuildXRefException: This file appears to be damaged and cannot be repaired. This may not actually be a PDF file.

com.adobe.acrobat.pdfobjstore.XRefTableRebuilder.buildTrailerDict(XRefTableRebuilder.java:141)

com.adobe.acrobat.pdfobjstore.XRefTableRebuilder.rebuildXRefTable(XRefTableRebuilder.java:121)

com.adobe.acrobat.pdfobjstore.XRefTableRebuilder.<init>(XRefTableRebuilder.java:46)

com.adobe.acrobat.pdfobjstore.XRefTable.<init>(XRefTable.java:44)

com.adobe.acrobat.pdfobjstore.XRefTable.<init>(XRefTable.java:64)

com.adobe.acrobat.pdfobjstore.PDFObjMap.compute(PDFObjMap.java:122)

com.adobe.pe.notify.VValue.handleRequest(VValue.java:172)

com.adobe.acrobat.pdfobjstore.PDFObjMap.getTrailerDictRef(PDFObjMap.java:49)

com.adobe.acrobat.pdfobjstore.VTrailerDict.computeReference(PDFObjStore.java:552)

com.adobe.acrobat.pdfobjstore.VPDFReference.compute(VPDFReference.java:150)

com.adobe.pe.notify.VValue.handleRequest(VValue.java:172)

com.adobe.acrobat.pdfobjstore.VPDFReference.pdfReferenceValue(VPDFReference.java:161)

com.adobe.acrobat.pdfobjstore.security.VEncryptionMethod.computeString(SecurityHandler.java:208)

com.adobe.pe.vtypes.VString.compute(VString.java:55)

com.adobe.pe.notify.VValue.handleRequest(VValue.java:172)

com.adobe.pe.vtypes.VString.stringValue(VString.java:126)

com.adobe.acrobat.pdfobjstore.security.VPDFObjStorePerms.computePDFObjStorePerms(VPDFObjStorePerms.java:41)

com.adobe.acrobat.pdfobjstore.security.VPDFObjStorePerms.compute(VPDFObjStorePerms.java:54)

com.adobe.pe.notify.VValue.handleRequest(VValue.java:172)

com.adobe.acrobat.pdfobjstore.security.VPDFObjStorePerms.peObjStorePermsValue(VPDFObjStorePerms.java:32)

com.adobe.acrobat.gui.AcroViewContext.setByteArraySource(AcroViewContext.java:587)

com.adobe.acrobat.Viewer$3.buildChanges(Viewer.java:907)

com.adobe.pe.notify.Transactor.commit(Transactor.java:70)

com.adobe.acrobat.Viewer.setByteArraySource(Viewer.java:911)

com.adobe.acrobat.Viewer.setDocumentByteArray(Viewer.java:948)

com.adobe.acrobat.Viewer.setDocumentInputStream(Viewer.java:971)

org.apache.jsp.uploadPDF_jsp._jspService(uploadPDF_jsp.java:106)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)

com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)

com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)

com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)

com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)

com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)

javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)

org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)

******************************

on the first line it says that the file may be corrupted but it is fine and works, thanks

moh

moh_1_and_onlya at 2007-7-9 6:17:50 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
you said you are trying to submit a tex file, and why does your servlet invoke the Acrobat APIs to load a PDF file? does tex and pdf open in acrobat, am not familiar with latex...
ganesh_renganathana at 2007-7-9 6:17:50 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
....Message was edited by: moh_1_and_only
moh_1_and_onlya at 2007-7-9 6:17:50 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
appy77 or can anybody help pls
moh_1_and_onlya at 2007-7-9 6:17:50 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

:-) ,

A few things

1) In your Javascript you are only checking for

if (ext = "pdf"){

document.forms[0].action.value = "uploadPDF.jsp";

allowSubmit = true;

break;

}

Similarly you need to add code in your Javascript to check for the other extensions for example

else if (ext = "LATEX"){

document.forms[0].action.value = "uploadLATEX.jsp";

allowSubmit = true;

break;

}

similarly for TXT

2) Post the code for your JSP pages, the one that handles PDF and the other that handles LATEX, that will help in tracing the exception, so only post relevant code.

3) Are you able to open the PDF or Latex file in their appropriate readers without any problems?

Message was edited by:

appy77

appy77a at 2007-7-9 6:17:50 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...