在JSP中使用JavaBean时出现异常

发布于 2025-01-01 14:12:21 字数 1384 浏览 4 评论 0原文

我无法解决这个问题,你能帮我吗?

<%@ 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>

异常:严重:servlet [jsp] 的 Servlet.service() 在上下文中 路径 [/Servlet_Projesi] 抛出异常 [/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;
    }
}

在此处输入图像描述

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.

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;
    }
}

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

遇见了你 2025-01-08 14:12:21

尝试在显示时使用 设置属性

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

,您可以使用 <%=musteri.getIsim() %>

try to set the property by using <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() %>

梅窗月明清似水 2025-01-08 14:12:21

有两点你可以尝试一下。

[1]初始化你的类属性,如

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

[2][非强制]实现可序列化,如

public class MusteriBean Implements java.io.Serialized

Two points you can give a try.

[1]Initialise your class properties like

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

[2][Not mandatory]implement Serializable like

public class MusteriBean implements java.io.Serializable

终止放荡 2025-01-08 14:12:21

我还找到了另一个解决方案。

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

我将其更改为:

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

并且有效..

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..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文