JSP 错误 "Illegal start of type"

JSP Error "Illegal start of type"

我正在尝试为 HTML-Form 运行ning 获取一个 JSP-File,但我遇到了以下问题: 当我尝试在测试服务器 (运行 LiveLink) 上 运行 此文件时,出现错误,提示:


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

这就是我的 JSP- 文件的样子

<%@ 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();
}
%>

我已经检查过是否缺少括号,但据我所知,缺少 none。

我不知道它是否重要,但服务器是 运行ning Java 1.4.2_19(无法更新),如您所见, JSP 还包含 iText 功能。

是我在代码本身犯了错误,还是我没有想到的原因?

这应该是一个 servlet,而不是 JSP。 JSP 应包含 HTML 代码和 JSP 标签。不是 Java 代码。

关于您的问题:您的代码已转换为 class,如下所示:

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

    try {
        //...

这显然是无效的。 try 块必须在方法内部。不是直接在class.

但我再说一遍:不要对 Java 代码使用 JSP。使用一个小服务程序。这就是他们的目的。