Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

How to display values from database to html page using servlet

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to display values form database to html page using servlet how can do this...
 
Ranch Hand
Posts: 129
Netbeans IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Expression tags are used to display information on JSP.

 
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is your question exactly? How to get the data from a database or how to display the retrieved data?
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
write in servlet...
String details="";
details = "<html> <body>";
details = details + "<table border=1><tr><td><Strong>Roll No <td>:</td> </Strong></td><td>" + sr.getRollno() + "</td></tr><br></br><tr><td><Strong>Name <td>:</td> </Strong></td><td>" + sr.getName() + "</td></tr><br></br><tr><td><Strong>Password <td>:</td> </Strong></td><td>" + sr.getPassword() + "</td></tr><br></br><tr><td><Strong>Mobile No <td>:</td> </Strong></td><td>" + sr.getContact1() + "</td></tr></table>";
details += "</body></html>";


first get the values from database and then put it instead of sr.getRollno() and so on..........
 
Sheriff
Posts: 67620
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nitin Surana wrote:Expression tags are used to display information on JSP.


No they are not. At last not in 2012. That notation was discredited 10 years ago. 10 years!

Time to update your JSP knowledge with the JSTL and EL. 10 years is long enough, don't you think?
 
Bear Bibeault
Sheriff
Posts: 67620
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

yogesh g gaikwad wrote:write in servlet...


Again, no.

Creating HTML in a servlet is a horrible practice.

Gather the data from the DB, store it in Java collections, add the collections to the request as scoped variables, and forward to a JSP to create the view.
 
Nitin Surana
Ranch Hand
Posts: 129
Netbeans IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:
Time to update your JSP knowledge with the JSTL and EL. 10 years is long enough, don't you think?



I do agree with you.
I said expression tag taking him to be a beginner. You don't expect a beginner to directly start with JSTL and EL. Atleast I don't expect that.
 
Bear Bibeault
Sheriff
Posts: 67620
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nitin Surana wrote:

Bear Bibeault wrote:
Time to update your JSP knowledge with the JSTL and EL. 10 years is long enough, don't you think?


I said expression tag taking him to be a beginner. You don't expect a beginner to directly start with JSTL and EL.


I absolutely do! Scriptlets are not for beginners -- they are old technology. Beginnners should learn the new technologies and develop good habits right away. Why should they learn something that they're not supposed to use? Why instill bad practices and bad habits at the outset?

Would you suggest that Java beginners learn Java 1.1 rather than Java 6 or 7?

Java code in a JSP is a bad practice for beginners and the experienced alike, and should never, ever, be used in any web page created after 2002.
 
Hussein Baghdadi
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nitin Surana wrote:

Bear Bibeault wrote:
Time to update your JSP knowledge with the JSTL and EL. 10 years is long enough, don't you think?



I do agree with you.
I said expression tag taking him to be a beginner. You don't expect a beginner to directly start with JSTL and EL. Atleast I don't expect that.


My guitar teacher is so strict when it comes to develop the right technique from the very beginning, because it is hard to get ride off the bad habits.
JSTL and JSP EL aren't really challenging after all.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic