0

我正在尝试创建一个简单的 JSP 页面,该页面导入一个作为 sax 解析器的 java 类。在 XMLReader 的实例化上部署应用程序时出现错误。我已经使用 main 方法对其进行了测试,以确保 java 正常工作。我忘记了配置设置吗?下面是我的 JSP 页面和我的班级。

页面

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="com.xml.XMLReader" %>
<%@page import="com.xml.Weather" %>
<%@page import="java.util.ArrayList" %>

<!DOCTYPE html>

<jsp:useBean id="xmlReader" class="XMLReader" scope="session" />

<%
  XMLReader reader = new XMLReader();
  ArrayList<Weather> list;
  list = reader.readXML();

%>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Weather Application</title>
    </head>
    <body>
        <p>test</p>
    </body>
</html>

XMLReader 类缩写

public class XMLReader extends DefaultHandler implements java.io.Serializable {

    //variable declarations
    private Weather weather;
    private ArrayList<weather> weatherList = new ArrayList<weather>();
    private String data;

    public XMLReader() {}

    public ArrayList<CityWeather> readXML() throws ParserConfigurationException, SAXException, IOException {
        SAXParserFactory saxFactory = SAXParserFactory.newInstance(); 
        SAXParser sp = saxFactory.newSAXParser();

        XMLReader handler = new XMLReader();

        sp.parse("Weather.xml", handler);

        return handler.getList();

    }

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attributes) 
        throws SAXException {

     ....
    }

    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException {

   ...
    }

     @Override
    public void characters(char[] buffer, int start, int length) {
        data = new String(buffer, start, length);
    }
}

编辑:这是错误堆栈跟踪

java.lang.InstantiationException: XMLReader
    at org.apache.jsp.index_jsp._jspService(index_jsp.java from :64)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:492)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:378)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:662)
4

1 回答 1

0

很抱歉造成混乱,我做了一个干净/构建,并且由于某种原因它起作用了。我以前曾尝试过,但由于某种原因它没有采取。感谢您的帮助。

于 2013-04-29T16:42:16.410 回答