我正在尝试运行一个运行HTML表单的JSP文件,但是我遇到了以下问题: 当我尝试在testserver上运行此文件(使用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-File的样子
<%@ 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功能。
我在代码本身中是否犯了错误,或者这可能是我想不到的不同之处?
答案 0 :(得分:5)
这应该是一个servlet,而不是JSP。 JSP应包含HTML代码和JSP标记。不是Java代码。
关于您的问题:您的代码将转换为如下所示的类:
public class TransformedJsp {
HashMap pdfOutputs = new HashMap();
// ...
try {
//...
这显然是无效的。 try块必须在方法内。不是直接在课堂上。
但我再说一遍:不要使用JSP代码来实现Java代码。使用servlet。这就是他们的目标。