JSP 错误 "Illegal start of type"



我正在尝试为正在运行的HTML表单获取JSP文件,但是我遇到了以下问题:当我尝试在测试服务器上运行此文件(使用 LiveLink 运行)时,出现错误,说:


500 Servlet Exception
/WebApps_e/WebApps/FORMS/Formular_Softwareantrag/PDFTest/PDFTest.jsp:34:
illegal start of type
    try
    ^
f:wcmwebsiteWEB-INFwork_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();
}
%>

我已经检查了缺少的括号,但据我所知,没有缺少括号。

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

我在代码本身中犯了错误,还是造成这种情况的原因与我没有想到的不同原因?

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

关于你的问题:你的代码被转换为一个类,看起来像这样:

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

这显然是无效的。try 块必须位于方法内。不直接在课堂上。

但我再说一遍:不要在Java代码中使用JSP。使用 servlet。这就是他们的目的。

相关内容

最新更新