[英]JSP Error “Illegal start of type”
I'm trying to get a JSP-File for a HTML-Form running, but I've got the following problem: When I try to run this file on a testserver (running with LiveLink), an error appears, saying: 我试图获取运行HTML表单的JSP文件,但遇到以下问题:当我尝试在测试服务器上运行该文件(使用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
This is how my JSP-File looks like 这就是我的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();
}
%>
I've already checked for missing parentheses, but as far as I can tell, none is missing. 我已经检查了缺失的括号,但据我所知,没有缺失。
I don't know if it's important, but the server is running Java 1.4.2_19 (can't update it) and, as you can see, the JSP also contains iText functionalities. 我不知道它是否重要,但是服务器正在运行Java 1.4.2_19(无法更新),并且如您所见,JSP还包含iText功能。
Is there a mistake I made in the code itself, or can the reason for this be something different I haven't thought of? 我在代码本身中犯了一个错误,还是原因可能是我没有想到的不同?
This should be a servlet, not a JSP. 这应该是servlet,而不是JSP。 A JSP should contain HTML code and JSP tags. JSP应该包含HTML代码和JSP标记。 Not Java code. 不是Java代码。
Regarding your question: your code is transformed to a class which looks like this: 关于您的问题:您的代码被转换为如下所示的类:
public class TransformedJsp {
HashMap pdfOutputs = new HashMap();
// ...
try {
//...
And that's obviously invalid. 这显然是无效的。 A try block must be inside a method. try块必须在方法内部。 Not directly in the class. 不是直接在班上。
But I repeat: don't use a JSP for Java code. 但我重复一遍:不要将JSP用于Java代码。 Use a servlet. 使用Servlet。 That's what they're for. 那就是他们的目的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.