有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java目标不可访问,标识符“beanName”解析为null

我遇到了一个问题,我在任何地方都找不到问题

我的索引。xhtml页面是:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"   
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
    <title>Facelet Title</title>
</h:head>
<h:body>

    <h:form>
        <h:outputText value="Enter product name"/>
        <h:inputText value="#{user.name}" /> <br/>
        <h:outputText value="Enter qty"/>
        <h:inputText value="#{user.qty}" /> <br/>
        <h:outputText value="Enter price"/>
        <h:inputText value="#{user.price}" /> <br/>
        <h:commandButton value="Add item" action="#{user.add}" />
    </h:form>

</h:body>

用户。java页面是:

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;


@ManagedBean 
@RequestScoped
public class User {
private String name;
private int qty;
private double price;


public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public int getQty() {
    return qty;
}

public void setQty(int qty) {
    this.qty = qty;
}

public double getPrice() {
    return price;
}

public void setPrice(double price) {
    this.price = price;
}

public String add(){
    System.out.println("product inserted..");
    System.out.println(this.name+" "+this.qty+" "+this.price);
    return "Success";
}

}

当我运行它时 /index。xhtml@12,48 value=“#{obj.name}”:无法访问目标,标识符“obj”解析为null 错误被指责。请帮帮我。(玻璃鱼4.1)


共 (0) 个答案