【问题标题】:Cannot solve the problem javax.el.PropertyNotFoundException: Property [content] not found on type [java.lang.String]无法解决问题 javax.el.PropertyNotFoundException: Property [content] not found on type [java.lang.String]
【发布时间】:2018-09-24 03:17:05
【问题描述】:

我已经阅读了相同的问题解决方案,但对我没有帮助。 我的 Bean 类中有一部分写得很好:

@Entity
@Table(name = "notes")
public class Note {
    @Id
    @GeneratedValue (strategy = GenerationType.IDENTITY)
    @Column (name = "id")
    private int id;    
    @Column (name = "content")
    private String content;


    public Note() {
    }

    public Note(String title, String content, GregorianCalendar date, boolean done) {
        this.title = title;
        this.content = content;
        this.date = date;
        this.done = done;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }    

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    } 
}

使用调试模式我可以看到,我已经从数据库中获得了我的 ArrayList 注释。这意味着,这种联系很好。有一个来自 servlet 的代码:

public static final String OUTPUT_LIST = "List For Pager";

// other code, not nessesary for showing  

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            Integer pageNumber =  (Integer) req.getAttribute(PAGE_NUMBER);
            if(pageNumber==null) pageNumber = 1;
            ArrayList<Note> result = new ArrayList<Note>();
            ArrayList<Note> notes = DaoDriver.getActualNotesHandler().getNotesList();
            //iteration method for filling result
            fillListForPage(pageNumber,notes,result);
            req.setAttribute(OUTPUT_LIST,result);
            RequestDispatcher requestDispatcher = req.getRequestDispatcher("/index_test.jsp");
            requestDispatcher.forward(req,resp);

有一个地方,我从 jsp 调用我的列表:

<c:forEach var="note" items="${MainServlet.OUTPUT_LIST}">

      <div class="row" padding="5" >
        <div class="card-deck">
          <div class="card">
            <div class="card-header">Title1</div>
            <div class="card-body"><p>${note.content}</p></div>
            <div class="card-footer">
              <input type="checkbox" class="Done">
              <label>Done</label>
              <button>Edit Note</button>
            </div>
          </div>

    </c:forEach>

我在这里还有其他问题,这可能会使我的应用程序崩溃。我有同样的情况,就像在这个问题中一样: JPA Cannot resolve column/IntelliJ

但我的数据已关联,快速修复无法解决此问题。

我的代码有什么问题?

UPD:我已经通过更改 2 个字符串解决了这个问题:

req.setAttribute("list",result);

<c:forEach var="note" items="${list}">

这就是为什么我有新问题:为什么我不能使用 MainServlet.class 中的静态最终字符串值(常量)作为请求属性的键?

【问题讨论】:

  • 您能否尝试简单地打印用于 forEach 之外且仅在 note 类内的项目的表达式的值?

标签: java hibernate jsp servlets jstl


【解决方案1】:

尝试将 ${MainServlet.OUTPUT_LIST} 更改为 ${requestScope.OUTPUT_LIST}

<c:forEach var="note" items="${requestScope.OUTPUT_LIST}">

【讨论】:

  • 没有帮助我(
  • 尝试删除jsp中的所有代码,只显示

    Test

    ,看看是否有效。
猜你喜欢
  • 2011-05-22
  • 1970-01-01
  • 1970-01-01
  • 2022-11-17
  • 1970-01-01
  • 2015-08-22
  • 1970-01-01
  • 2020-07-02
  • 2019-03-11
相关资源
最近更新 更多