Farid Movsumov
Farid Movsumov

Reputation: 12725

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.

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

Upvotes: 0

Views: 698

Answers (3)

Farid Movsumov
Farid Movsumov

Reputation: 12725

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

Upvotes: 1

Ravindra Gullapalli
Ravindra Gullapalli

Reputation: 9158

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

Upvotes: 1

Ramesh Kotha
Ramesh Kotha

Reputation: 8322

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() %>

Upvotes: 1

Related Questions