简体   繁体   English

在JSP中使用JavaBean时发生异常

[英]Exception while using JavaBean in JSP

I can't solve this problem can you help me please. 我无法解决这个问题,请您能帮我。

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<jsp:useBean id="musteri" class="beanler.MusteriBean" scope="request" ></jsp:useBean>

<%musteri.setIsim("Ferid");%>
<%=musteri.getIsim() %>
</body>
</html>

EXCEPTION: SEVERE: Servlet.service() for servlet [jsp] in context with path [/Servlet_Projesi] threw exception [/beanTest.jsp (line: 11, column: 0) The value for the useBean class attribute beanler.MusteriBean is invalid.] with root cause org.apache.jasper.JasperException: /beanTest.jsp (line: 11, column: 0) The value for the useBean class attribute beanler.MusteriBean is invalid. 例外:严重:路径为[/ Servlet_Projesi]的上下文中Servlet [jsp]的Servlet.service()引发了异常[/beanTest.jsp(第11行,第0列))useBean类属性beanler.MusteriBean的值无效。]的根本原因是org.apache.jasper.JasperException:/beanTest.jsp(行:11,列:0)useBean类属性beanler.MusteriBean的值无效。

package beanler;

public class MusteriBean {
    private String isim;
    private String soyad;

    public String getIsim() {
        return isim;
    }
    public void setIsim(String isim) {
        this.isim = isim;
    }
    public String getSoyad() {
        return soyad;
    }
    public void setSoyad(String soyad) {
        this.soyad = soyad;
    }
}

在此处输入图片说明

try to set the property by using <jsp:setProperty> 尝试使用<jsp:setProperty>设置属性

<jsp:useBean id="musteri" class="beanler.MusteriBean" scope="request" >
<jsp:setProperty name="musteri" property="isim" value=" Ferid" />
</jsp:useBean>

while displaying you can use <%=musteri.getIsim() %> 在显示时可以使用<%=musteri.getIsim() %>

Two points you can give a try. 您可以尝试两点。

[1]Initialise your class properties like [1]初始化您的课程属性,例如

private String isim = null;
private String soyad = null;

[2][Not mandatory]implement Serializable like [2] [非强制]实现可序列化,例如

public class MusteriBean implements java.io.Serializable

I also found another solution. 我还找到了另一种解决方案。

<jsp:useBean id="musteri" class="beanler.MusteriBean" scope="request" ></jsp:useBean>

I changed it to: 我将其更改为:

<jsp:useBean id="musteri" class="beanler.MusteriBean" scope="request" />

and that works.. 那行得通..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM