0

Hibernate、SERVLET、JSPを使用し、MySqlデータベースを使用してアプリケーションを開発しています。私のプロジェクトで使用されているテーブルはBeanRegisterです。

ここで、jspページでのELの使用に関する問題に直面しています。このJSPページでは、データベーステーブルから取得した情報を表示したいと思います。これが私のコードです。

ControllerProfile.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);
            }
        }
    }
}

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

これで、サーブレットクラスにアクセスしているときに、profile.jspが呼び出されます。ただし、フォームのテキストフィールドには、コーディング時のELコードがそのまま表示されます。なぜこれが機能しないのか、私は非常に混乱しています。

4

1 に答える 1

0
i think you use Tomcat 7
Tomcat 7 does not come with JSTL jar files by default.
   First, locate the jar files for both JSTL API and JSTL Implementation. They are located on the JSP Standard Tag Library download page. Click into each repository and find the .jar file.

Tomcat 7
           =>Servlet -api-3.0
           =>JSTL-1.2

 refer this link:http://javahelpersin.blogspot.in/2013_01_01_archive.html
于 2013-01-17T08:20:48.900 に答える