我正在尝试通过JSP页面编辑我的实体
<jsp:include page="menuEditarDisciplina.jsp">
<jsp:param name="idDisciplina" value='<%=request.getParameter("id")%>'/>
</jsp:include>
我正在使用的servlet代码
public class InsereDisciplina implements Logica {
private ClienteRestDisciplina clienteRestDisciplina;
private ClienteRestCurso clienteRestCurso;
public void executa(HttpServletRequest req, HttpServletResponse res)
throws Exception {
clienteRestDisciplina = new ClienteRestDisciplina();
clienteRestCurso = new ClienteRestCurso();
String idCursoS = req.getParameter("idCurso");
Integer idCurso = (idCursoS != null) ? Integer.parseInt(idCursoS)
: null;
String idProfessorS = req.getParameter("idProfessor");
Integer idProfessor = (idProfessorS != null) ? Integer
.parseInt(idProfessorS) : null;
String idDisciplinaS = req.getParameter("id");
Integer idDisciplina = (idDisciplinaS != null) ? Integer
.parseInt(idDisciplinaS) : null;
Disciplina disciplina = idDisciplina == null ? new Disciplina()
: clienteRestDisciplina.getDisciplina(idDisciplina);
disciplina.setNome(req.getParameter("nome"));
disciplina.setSala(Integer.parseInt(req.getParameter("sala")));
String dataString = req.getParameter("horario").toString();
disciplina.setHorario(Date.valueOf(dataString));
disciplina.setCargaHoraria(Integer.parseInt(req
.getParameter("cargaHoraria")));
disciplina.setDescricao(req.getParameter("descricao"));
if (disciplina.getIdDisciplina() != null) {
clienteRestDisciplina.editarDisciplina(disciplina);
} else {
clienteRestCurso.inserirDisciplinaNoCurso(idCurso, idProfessor,
disciplina);
}
res.sendRedirect("disciplina/listarDisciplinas.jsp");
}
}
我的Java bean类如下
@XmlRootElement
public class Disciplina implements Serializable {
private static final long serialVersionUID = 1L;
private Integer id;
public Disciplina() {
}
public Disciplina(Integer id) {
this.id = id;
}
public Disciplina(Integer id, String nome, String descricao, int cargaHoraria, Date horario, int sala) {
this.id = id;
this.nome = nome;
this.descricao = descricao;
this.cargaHoraria = cargaHoraria;
this.horario = horario;
this.sala = sala;
}
public Integer getIdDisciplina() {
return id;
}
public void setIdDisciplina(Integer idDisciplina) {
this.id = idDisciplina;
}
// ...
}
但它有一个例外:
javax.el.PropertyNotFoundException: The class 'br.icmc.usp.modelo.Disciplina' does not have the property 'id'.
at javax.el.BeanELResolver.getBeanProperty(BeanELResolver.java:664)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:293)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:188)
at com.sun.el.parser.AstValue.getValue(AstValue.java:120)
at com.sun.el.parser.AstValue.getValue(AstValue.java:167)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:224)
at org.apache.jasper.runtime.PageContextImpl.evaluateExpression(PageContextImpl.java:1009)
at org.apache.jsp.disciplina.editarDisciplina_jsp._jspService(editarDisciplina_jsp.java:99)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:492)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:378)
为什么我收到PropertyNotFoundException
个例外?我哪里错了?
答案 0 :(得分:2)
这似乎与EL相关的错误。不是scriptlet代码错误。 EL适用于getter setter。
更改你的getter setter
public Integer getIdDisciplina() {
return id;
}
public void setIdDisciplina(Integer idDisciplina) {
this.id = idDisciplina;
}
到
public Integer getId() {
return id;
}
public void setId(Integer idDisciplina) {
this.id = idDisciplina;
}