JNDI – select data from database through JSTL tags.

In last post I describe how configure GlassFish server for JNDI resource ( SQL Server 2012 database ). So In this post we test it in application.

Open Netbeans IDE. Create new project. Click File and choose New Project.

a1The New Project window appear. From Categories select Java Web and from Projects section choose Web Application.

a2Click the Next button. In New Web Application window in Project Name field write JSTLTest.

Click the Next button.

In next step click Next button.

Click Finish button. In Projects window You see your JSTLTest project.

Delete from Web Pages node index.html file.

And then You must configure your application adding DataSource for SQL Server database. So right click your project node and choose New->Other.

In New File window from Categories choose Web and form File Types select Standard Deployment Descriptor(web.xml)

Click the Next button. New configuration data appear.

Click the Finish button.

The web.xml file opened.

It is configuration file so it places in Configuration Files node.

Click the References tab.

After click the Add button You see dialog window.

In Resource Name write name of JDBC Resource configured in GlassFish server.

It was in GlassFish jdbc/sql2012:

In Resource References display row with data.

Click the Source tab.

Configuration file is prepared. Create index.jsp file. Right click Web Pages node and choose New->JSP.

In File Name field write index.

Click the Finish button.

You see content:

Change this html content. Paste into it this new content:







    
        
        Persons
    
    
        

List of persons:

                SELECT id,name FROM mytest                                                                                                                                                                                                                                                                 
id name
${person.id} ${person.name}
   

Your index.jsp file:

Run application.

Browser display list of person from SQL Server.