简体   繁体   中英

How to retrieve specific data contents in database from servlet to jsp using java?

I am developing one web application and following MVC pattern and using hibernate and postgresql.I have data in my data base tables.Now my servlet retrieves the data from data base by accessing bean classes using select statement and returns as a list.And in my jsp I have drop down list.If I select one option from that then the data related to that option should be displayed on the browser.How can I achieve this.I am new to JSP.Please help me.I know I can display it using ${}.But using which statement I am able to access data of selected option from drop down list. For Example in my application if I select one option say "XYZ" then I should get only XYZ details from Person table.How to achieve this.

And one more doubt is only specific values like name and roll number only these two values related to XYZ from Person table I should get.

Please clarify these two doubts. Thank you.

You should use the core taglib - so add this at the top of the JSP page :

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>  

Then eg (where "users" is for example a List of objects with a public getName() method):

<ul>
    <c:forEach var="item" items="${users}">
        <li>    
             <c:out value="${user.name}"/>
        </li> 
    </c:forEach>
</ul>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM