2015-01-23 2 views
0

HTML-Form 실행을위한 JSP 파일을 가져 오려고하는데 다음과 같은 문제가 있습니다. 이 파일을 테스트 서버에서 실행하려고하면JSP 오류 "형식이 잘못되었습니다."


500 Servlet Exception 

/WebApps_e/WebApps/FORMS/Formular_Softwareantrag/PDFTest/PDFTest.jsp:34: 
illegal start of type 

    try 
    ^
f:\wcm\website\WEB-INF\work\_jsp\_webapps_0e\_webapps\_forms\_formular_0softwareantrag\_pdftest\_pdftest__jsp.java:319: 

<identifier> expected 
    private java.util.ArrayList _caucho_depends = new java.util.ArrayList(); 
                     ^

2 errors 

이것은 이미 채널했습니다

<%@ page import=" 
java.util.*, 
java.util.HashMap, 
java.net.URL, 
java.io.*, 
javax.mail.*, 
javax.mail.internet.*, 
javax.activation.*, 
de.gauss.vip.portalmanager.VipObjectBean, 
de.gauss.vip.repository.RepositoryEntry, 
de.gauss.lang.StringValue, 
de.gauss.vip.api.admin.Server, 
com.lowagie.text.*, 
com.lowagie.text.pdf.*, 
com.caucho.vfs.* 
" %> 
<%! 
HashMap pdfOutputs = new HashMap(); 
Document document = null; 
PdfReader reader = null; 
PdfStamper stamper = null; 
AcroFields acro_fields = null; 
ByteArrayOutputStream bostream = null; 

try 
{ 
    vobFORMS.setRepositoryName("{VIPDEPLOYMENT_NAME}"); 
    vobFORMS.addDefaultAttribute("pathname"); 

    /** Check for standart attributes */ 
    String template = request.getParameter("TEMPLATE"); 
    if (template == null) 
    { 
     throw new Exception("TEMPLATE-Parameter fehlt!"); 
    } 

    /** Collecting the parameters in a HashMap */ 
    Enumeration param_names_enum = request.getParameterNames(); 
    while (param_names_enum.hasMoreElements()) 
    { 
     String param = (String)param_names_enum.nextElement(); 
     if (param != null) 
     { 
      /** Wert des Parameters holen */ 
      String param_value = request.getParameter(param); 
      if (param_value != null) 
      { 
       pdfOutputs.put(param, param_value); 
      } 
     } 
    } 

    /** Handling the Data */ 
    /** 1. Load the PDF-Template */ 
    String filename = null; 
    RepositoryEntry repHelp = vobFORMS.getEntry(template); 

    if (repHelp != null) 
    { 
     filename = ((StringValue)repHelp.getValue("pathname")).getString(); 
    } 
    if (filename == null) 
    { 
     throw new Exception("PDF-Template could not be found!"); 
    } 

    reader = new PdfReader(filename); 
    int rotation = reader.getPageRotation(1); 

    if (rotation == 90 || rotation == 270) 
    { 
     document = new Document(PageSize.A4.rotate()); 
    } 
    else 
    { 
     document = new Document(PageSize.A4); 
    } 

    /** 2. Appending the writer */ 
    bostream = new ByteArrayOutputStream(); 
    PdfWriter writer = PdfWriter.getInstance(document, bostream); 

    /** 3. Opening the Document */ 
    document.open(); 

    /** 4. Appending the content */ 
    PdfContentByte cb = writer.getDirectContent(); 
    PdfImportedPage pdfpage = writer.getImportedPage(reader, 1); 

    if (rotation == 90 || rotation == 270) 
    { 
     cb.addTemplate(pdfpage,0,-1,1,0,0,595f); 
    } 
    else 
    { 
     cb.addTemplate(pdfpage,1,0,0,1,0,0); 
    } 

    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); 
    cb.beginText(); 
    cb.setFontAndSize(bf, 12); 

    stamper = new PdfStamper(reader, pdfpage); 
    acro_fields = stamper.getAcroFields(); 

    /** Iteration through the HashMap */ 
    for (String key : pdfOutputs.keySet()) 
    { 
     acro_fields.setField(key, pdfOutputs.get(key)); 
    } 

    /** End of the form-fields */ 
    cb.endText(); 

    /** 5. Closing the document */ 
    document.close(); 
} 
catch(Exception ex1) 
{ 
    out.println("An Error occured while handling the data<br>"); 
    out.println(ex1.getMessage()); 
} 
finally 
{ 
    if (stamper != null) 
     stamper.close(); 
    if (pdfOutputs != null) 
     pdfOutputs.clear(); 
    if (reader != null) 
     reader = null; 
    if (document != null) 
     document.close(); 
    if (bostream != null) 
     bostream.close(); 
} 
%> 

처럼 내 JSP - 파일이 모습입니다 : LiveLink를)로, 오류가 말하는 나타납니다 누락 된 괄호를 찾지 못했지만, 내가 말할 수있는 한 아무도 빠져있다.

중요한지는 모르겠지만 서버가 Java 1.4.2_19 (업데이트 할 수 없음)를 실행하고 있으며, 볼 수있는 것처럼 JSP에 iText 기능도 포함되어 있습니다.

코드 자체에 실수가 있습니까? 아니면이 이유가 다른 생각 일 수 있습니까?

답변

5

JSP가 아닌 서블릿이어야합니다. JSP에는 HTML 코드와 JSP 태그가 있어야합니다. Java 코드가 아닙니다. 코드는 다음과 같습니다 클래스로 변환 :

public class TransformedJsp { 
    HashMap pdfOutputs = new HashMap(); 
    // ... 

    try { 
     //... 

을 그리고 그것은 분명히 잘못된이다

질문에 대해서는. try 블록은 메소드 안에 있어야합니다. 직접 수업에 참여하지 마십시오.

하지만 반복합니다. Java 코드에 JSP를 사용하지 마십시오. 서블릿을 사용하십시오. 그것이 바로 그들이 원하는 것입니다.

+0

빠른 답장을 보내 주셔서 감사합니다. – suby125

관련 문제