gpt4 book ai didi

jsp - java.lang.NoSuchMethodError : uges. servlets.MyQuery: 找不到方法 ()V

转载 作者:行者123 更新时间:2023-11-28 22:44:49 25 4
gpt4 key购买 nike

我正在使用 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 catalog.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>

任何线索将不胜感激。谢谢,

最佳答案

JSP 引擎正在尝试使用无参数构造函数通过反射来实例化您的类。您尚未定义无参数构造函数,因此会发生此错误。 bean 必须具有无参数构造函数。如果您需要在 bean 上设置属性,请使用 jsp:set-property

如果您绝对不能添加无参数构造函数,那么您必须在 jsp:use-bean 标记之外实例化它,并自己将其添加到适当的上下文中,如

< %   
pkg.Foo foo = new pcg.Foo(constructor-arg);
context.setAttribute("foo", foo);
% >

这违反了无参数构造函数的基本 JavaBean 要求。

我相信一旦在适当的范围内创建它,其他 JSP 就可以使用 jsp:use-bean 引用它。

关于jsp - java.lang.NoSuchMethodError : uges. servlets.MyQuery: 找不到方法 <init>()V,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10540753/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com