回 帖 发 新 帖 刷新版面

主题:各位高手看看咋解决这个问题?

错误如下:
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 4 in the jsp file: /order.jsp
Generated servlet error:
C:\Documents and Settings\lee\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\work\Catalina\localhost\shop\org\apache\jsp\order_jsp.java:68: setUserID(java.lang.String) in cuug.OrderBean cannot be applied to (java.lang.Object)
orderBean.setUserID( session.getValue("memberID") );
         ^


An error occurred at line: 4 in the jsp file: /order.jsp
Generated servlet error:
Note: C:\Documents and Settings\lee\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\work\Catalina\localhost\shop\org\apache\jsp\order_jsp.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
1 error
*****************************************
order.jsp :
<%@ page language="java" contentType="text/html; charset=gb2312"%>
<jsp:useBean class="cuug.BookBean" id="bookinfo" scope="page"></jsp:useBean>
<jsp:useBean class="cuug.OrderBean" id="orderBean" scope="page"></jsp:useBean>
<%
/*禁止使用浏览器Cache,网页立即失效*/
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires",0);
orderBean.setUserID( session.getValue("memberID") );
%>
<HTML>
<HEAD>
<META http-equiv="Content-Style-Type" content="text/css">
<TITLE>
填写订单
</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">

</BODY>
</HTML>
******************************************
OrderBean.java:
package cuug;
import java.sql.*;

public class OrderBean {
 
    private static String strDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
    private static String strDBUrl = "jdbc:odbc:booksore";
    private Connection conn=null;
    private ResultSet rs = null;
    private java.lang.String bookinfo =null;
    private java.lang.String Orderprice = null;
    private java.lang.String orderDate = null;
    private java.lang.String orderID = null;
    private java.lang.String orderRem = null;
    private java.lang.String receiverAddress = null;
    private java.lang.String receiverName = null;
    private java.lang.String receiverZip = null;
    private java.lang.String UserID = null;
    
    public OrderBean(){
        try{
            Class.forName(strDBDriver);
        }
        catch(java.lang.ClassNotFoundException e){
            System.err.println("OrderBean.getLogontimes():"+e.getMessage());
        }
    }
    
    public java.lang.String getOrderprice() {
        return Orderprice;
}

/**
 *返回定单的日期 。
 * @return Java.lang.String
 */
public java.lang.String getOrderDate() {
        orderDate = new java.util.Date().toString();
        return orderDate;
}

/**
 * 返回定单的ID号。
 * @return Java.lang.String
 */
public java.lang.String getOrderID() {
        return orderID;
}


public java.lang.String getReceiverName() {
        return receiverName;
}

/**
 * 返回接收者的邮政编码。
 * @return Java.lang.String
 */
public java.lang.String getReceiverZip() {
        return receiverZip;
}

/**
 * 获得用户ID。
 * @return Java.lang.String
 */
public java.lang.String getUserID() {
    return UserID;
}



public void setBookinfo(java.lang.String newBookinfo) {
        bookinfo = newBookinfo;
        createNewOrder();
        int fromIndex = 0;
        int tmpIndex = 0;
        int tmpEnd = 0;
        String strSql = null;
        try{
            conn = DriverManager.getConnection(strDBUrl);
            Statement stmt = conn.createStatement();
            System.out.println(fromIndex+"====");
            while(bookinfo.indexOf(';',fromIndex) != -1 ){
                tmpEnd = bookinfo.indexOf(';',fromIndex);
                tmpIndex = bookinfo.lastIndexOf('=',tmpEnd);
                strSql = "insert into orderdetail(orderID,bookISBN,bookcount) values("+ getOrderID()+ ", '" + bookinfo.substring(fromIndex ,tmpIndex) + "','" + bookinfo.substring(tmpIndex+1 ,tmpEnd) + "')" ;
                stmt.executeUpdate(strSql);
            fromIndex = tmpEnd + 1;
            
            }
            stmt.close();
            conn.close();
            System.out.println(strSql+"asdf");
        }
        catch(SQLException e){
            System.err.println( e.getMessage());
        }
}

public void setUserID(java.lang.String newUserID) {
    UserID = newUserID;
}


public static void main(String args[])
{
    System.out.println("asdf");
    //OrderBean buyer = new OrderBean();
    //buyer.createNewOrder();
}
}






回复列表 (共5个回复)

沙发

order.jsp :
orderBean.setUserID((String)session.getValue("memberID"));

板凳

已解决,Ok
orderBean.setUserID("'"+ session.getValue("memberID")+"'" );

3 楼

又遇到一个错误
javax.servlet.ServletException: Unresolved compilation problem: 
    The method rs(String) is undefined for the type OrderBean

    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
    org.apache.jsp.order_jsp._jspService(order_jsp.java:253)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause 

java.lang.Error: Unresolved compilation problem: 
    The method rs(String) is undefined for the type OrderBean

    cuug.OrderBean.createNewOrder(OrderBean.java:191)
    cuug.OrderBean.setBookinfo(OrderBean.java:98)
    org.apache.jsp.order_jsp._jspService(order_jsp.java:93)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

******************
order.jsp:
<%@ page language="java" contentType="text/html; charset=gb2312"%>
<jsp:useBean class="cuug.BookBean" id="bookinfo" scope="page"></jsp:useBean>
<jsp:useBean class="cuug.OrderBean" id="orderBean" scope="page"></jsp:useBean>
<%
/*禁止使用浏览器Cache,网页立即失效*/
//response.setHeader("Pragma", "No-cache");
//response.setHeader("Cache-Control", "no-cache");
//response.setDateHeader("Expires",0);

%>
<HTML>
<HEAD>
<META http-equiv="Content-Style-Type" content="text/css">
<TITLE>
填写订单
</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<%if ("send".equals (request.getParameter("send")))
{
    
    orderBean.setUserID((String)session.getValue("memberID"));
    
    String str=request.getParameter("receivername");
    orderBean.setReceiverName(str==null?"":str);
    str=request.getParameter("Orderprice");
    orderBean.setOrderprice(str==null?"":str);
    str=request.getParameter("address");
    orderBean.setReceiverAddress(str==null?"":str);
    str=request.getParameter("postcode");
    orderBean.setReceiverZip(str==null?"":str);
    str=request.getParameter("bookinfo");
    orderBean.setBookinfo(str==null?"":str);
    str=request.getParameter("memo");
    orderBean.setOrderRem(str==null?"":str);
        int orderID=orderBean.getOrderID();
        if(orderID<0)
        {
            Cookie[] cookies=request.getCookies();
            for(int i=0;i<cookies.length;i++)
            {
                String isbn=cookies[i].getName();
                //if(isbn.startsWith("ISBN")&&isbn.length()==17)
                    if(isbn.startsWith("ISBN"))
                {
                    Cookie c =new Cookie(isbn,"0");
                    c.setMaxAge(0);
                    response.addCookie(c);
                }
            }
        
    %>
<p align="center">订购成功!</p>
<p align="center"> 订单号:<%=orderID%></p>
<p align="center"><a href="booklist.jsp">返回首页</a></p>
<%
        }
        else
        {
            out.print("订购失败\n");
        }

    }
else
{
    float price=0;
    String Bookinfo="";
    %>
</body>
</html>

OrderBean.java同上。
谢谢各位了

4 楼

错误是说order.jsp调用了OrderBean的一个不存在的方法:rs(Stirng)

5 楼

setUserID(java.lang.String) in cuug.OrderBean cannot be applied to (java.lang.Object)

orderBean.setUserID((String)session.getValue("memberID"));
这个错误你这个方法接受的参数类型不对!

我来回复

您尚未登录,请登录后再回复。点此登录或注册