我正在使用 Tomcat v 7 和 Jess v 7.0
这是我得到的例外
root cause
javax.servlet.ServletException: java.lang.NoSuchMethodError: uges.servlets.MyQuery: method <init>()V not found
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.jav a:911)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:840)
org.apache.jsp.catalog_jsp._jspService(catalog_jsp.java:121)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
java.lang.NoSuchMethodError: uges.servlets.MyQuery: method <init>()V not found
org.apache.jsp.catalog_jsp._jspService(catalog_jsp.java:69)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
这是我的 MyQuery 类包 uges.servlets 的源代码;
import jess.*;;
public class MyQuery
{
private static QueryResult result;
public MyQuery(Rete engine) throws JessException
{
getQuery(engine);
}
public QueryResult getQuery(Rete engine) throws JessException
{
result = engine.runQueryStar("all-products", new ValueVector());
return result;
}
public String getString(String str) throws JessException
{
String srtResult;
srtResult = result.getString(str);
return srtResult;
}
public Float getFloat(String str) throws JessException
{
float flt;
flt = result.getFloat(str);
return flt;
}
public boolean next() throws JessException
{
boolean next;
next = result.next();
return next;
}
}
这是目录 Servlet 包 uges.servlets;
import jess.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Catalog extends BaseServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
checkInitialized();
try {
String customerId =
(String) request.getParameter("customerId");
if (customerId == null || customerId.length() == 0) {
dispatch(request, response, "/index.html");
return;
}
request.getSession().invalidate();
HttpSession session = request.getSession();
session.setAttribute("customerId", customerId);
session.setAttribute("orderNumber",
String.valueOf(getNewOrderNumber()));
ServletContext servletContext = getServletContext();
Rete engine = (Rete) servletContext.getAttribute("engine");
//engine.reset();
MyQuery result = new MyQuery(engine);
//engine.runQueryStar("all-products", new ValueVector());
request.setAttribute("queryResult",result);
} catch (JessException je) {
throw new ServletException(je);
}
dispatch(request, response, "/catalog.jsp");
}
private int getNewOrderNumber() throws JessException {
ServletContext servletContext = getServletContext();
Rete engine = (Rete) servletContext.getAttribute("engine");
int nextOrderNumber =
engine.executeCommand("(get-new-order-number)").intValue(null);
return nextOrderNumber;
}
public void destroy() {
try {
ServletContext servletContext = getServletContext();
Rete engine = (Rete) servletContext.getAttribute("engine");
String factsFileName =
servletContext.getInitParameter("factsfile");
File factsFile = new File(factsFileName);
File tmpFile =
File.createTempFile("facts", "tmp", factsFile.getParentFile());
engine.executeCommand("(save-facts " + tmpFile.getAbsolutePath() +
" order recommend line-item next-order-number)");
factsFile.delete();
tmpFile.renameTo(factsFile);
} catch (Exception je) {
// Log error
}
}
}
JSP 目录.jsp
<HTML>
<%@ page import="jess.*" %>
<jsp:useBean id="queryResult" class="uges.servlets.MyQuery" scope="request"/>
<HEAD>
<TITLE>Ordering from Tekmart.com</TITLE>
</HEAD>
<BODY>
<H1>Tekmart.com Catalog</H1>
Select the items you wish to purchase and press "Check Order" to continue.
<FORM action="/Order/recommend" method="POST">
<TABLE border="1">
<TR><TH>Name</TH>
<TH>Catalog #</TH>
<TH>Price</TH>
<TH>Purchase?</TH>
</TR>
<% while (queryResult.next()) {
String partNum =
queryResult.getString("part-number");%>
<TR>
<TD><%= queryResult.getString("name") %></TD>
<TD><%= queryResult.getString("part-number") %></TD>
<TD><%= queryResult.getFloat("price") %></TD>
<TD><INPUT type="checkbox" name="items"
value=<%= '"' + partNum + '"'%>></TD>
</TR>
<% } %>
</TABLE>
<INPUT type="submit" value="Check Order">
</FORM>
</BODY>
</HTML>
任何线索将不胜感激。谢谢,