我正在使用 Hibernate、SERVLET、JSP 和 MySql 数据库开发应用程序。我的项目中使用的表是 BeanRegister。
在这里,我遇到了在我的 jsp 页面中使用 EL 的问题。在这个 JSP 页面中,我想显示从数据库表中获取的一些信息。这是我的代码..
控制器配置文件.java:
import java.io.IOException;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.Query;
public class ControllerProfile extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if ((request.getParameter("accsub") != null)) {
if (request.getParameter("accuser") != null) {
Session session = null;
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
org.hibernate.Transaction tx = session.beginTransaction();
String i = request.getParameter("accuser");
String Q = " from BeanRegister where userid= :id ";
Query query = session.createQuery(Q);
query.setParameter("id", i);
List<BeanRegister> profile = query.list();
request.setAttribute("profile", profile);
tx.commit();
session.flush();
session.close();
RequestDispatcher dispatcher = request.getRequestDispatcher("profile.jsp");
dispatcher.forward(request, response);
} else {
System.out.println("error");
RequestDispatcher dispatcher = request.getRequestDispatcher("viewprofile.jsp");
dispatcher.forward(request, response);
}
}
}
}
配置文件.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
....
....
<form name="proview" id="proview" action="updateprofile.jsp" method="post" >
<div align="center">
<table width="366" border="0" bgcolor="#3333CC">
<c:forEach var="pro" items="${profile}">
<tr>
<td width="171" height="23"></td>
<td width="194"><input name="password" id="password" type="hidden" value="${pro.password}"/></td>
</tr>
<tr>
<td width="171" height="23"><div align="center">NAME</div></td>
<td width="194"><input name="name" type="text" id="name" value="${pro.name}" readonly="readonly"/></td>
</tr>
<tr>
<td width="171" height="23"><div align="center">USER ID</div></td>
<td width="194"><input name="userid" id="userid" type="text" value="${pro.userid}" readonly="readonly"/></td>
</tr>
<tr>
<td width="171" height="23"><div align="center">ADDRESS</div></td>
<td><input type="text" name="address" id="address" value="${pro.address}" readonly="readonly"/></td>
</tr>
<tr>
<tr>
<td width="171" height="23"><div align="center">GENDER</div></td>
<td width="194"><input name="sex" type="text" id="sex" value="${pro.sex}" readonly="readonly"/></td>
</tr>
</tr>
<tr>
<td width="171" height="23"><div align="center">MOBILE NUMBER</div></td>
<td><input name="number" type="text" id="number" value="${pro.number}" readonly="readonly"/></td>
</tr>
<tr>
<td width="171" height="23"><div align="center">EMAIL ID</div></td>
<td><input name="email" id="email" type="text" value="${pro.email}" readonly="readonly"/></td>
</tr>
<tr>
<td width="171" height="23"></td>
<td width="185"><input name="password1" id="password1" type="hidden" value="${pro.password1}"/></td>
</tr>
<tr>
<td>
<div align="center">
Want To Edit Ur Profile Click Here
</div></td>
<td >
<div align="center">
<input type="submit" name="updateprof" id="updateprof" value="UPDATE" />
</div></td>
</tr>
</c:forEach>
</table>
</div>
</form>
</body>
</html>
现在,当我访问我的 servlet 类时,它会调用 profile.jsp。但是,表单的文本字段会显示编码中的 EL 代码。我很困惑为什么这不起作用。