• 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
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Getting started with JSP

 
Ranch Hand
Posts: 77
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm making a web based application for the first time. I am done with my HTML code and I have DB connections in Java me. I want to connect both using JSP. Being a noob, can someone please help with how should I get it started? What do i need to download and How do I bring it together? Please help.
 
Ranch Hand
Posts: 157
1
Android MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Noopur, please bring a controller(servlet) in picture. Dont try directly with jsp. Although you can write all your html+java code inside your jsp just put all your code inside <%%> scriplet, which will go inside service, and will do the job for you, but its not advisable. Let me know if you need some more clarification.
 
Nandita Tiwari
Ranch Hand
Posts: 77
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, a servlet instead of JSP?? Ok, I'll do R&D. By the way, how do i convert my java code into JSP and how do I connect this JSP to my HTML??
For servlet I need to use a IDE, right?? What else do I need?
 
harshvardhan ojha
Ranch Hand
Posts: 157
1
Android MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have fair idea of servlets, no need to use IDE. copy everything from html to jsp, thats fine, this way you can convert html to jsp page. In your action of jsp form just give url pattern of a servlet and call your working jdbc code.

ex.

MyServlet
<url-pattern>myserv</url-pattern>

from jsp page <form action="myserv"></form>

And you are done.

please follow MVC design pattern any exmple will work for you.
Hope this will help.

 
Ranch Hand
Posts: 30
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can think the JSPs files like a mixture of JAVA+HTML+ JSP TAGS.

What harshvardhan ojha is saying is that is a good practice to decouple the layers of the application. If you're doing R&D please read about the Model View Controller. Sure this will clear a lot of concepts.

 
Sheriff
Posts: 67645
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

Pablo Abbate wrote:You can think the JSPs files like a mixture of JAVA+HTML+ JSP TAGS.


Not quite. Putting Java in a JSP has been obsolete and discredited for 10 years. No Java code in JSPs!

 
Bear Bibeault
Sheriff
Posts: 67645
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
I always recommend that newcomers to JSP read:
  • The Secret Life of JSPs
  • The Front Man


  • The first explains how JSP works, the second how proper web apps should be structured.
     
    Nandita Tiwari
    Ranch Hand
    Posts: 77
    Netbeans IDE Oracle Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    where can I get a sample servlet code??
     
    Pablo Abbate
    Ranch Hand
    Posts: 30
    Spring Java Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Bear Bibeault wrote:

    Pablo Abbate wrote:You can think the JSPs files like a mixture of JAVA+HTML+ JSP TAGS.


    Not quite. Putting Java in a JSP has been obsolete and discredited for 10 years. No Java code in JSPs!



    We are not discussing best practices, he wants to know what can he do with JSP ...
     
    Sheriff
    Posts: 27235
    87
    Eclipse IDE Firefox Browser MySQL Database
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Pablo Abbate wrote:We are not discussing best practices, he wants to know what can he do with JSP ...



    But this is not some game where the task is to identify as many different ways to use a JSP as possible. The poster wants to learn about JSP, presumably so that he or she can use it to write web applications. Given that, the responsible thing is to identify best practices before the poster starts learning the less-than-best practices which are so lamentably common.
     
    Pablo Abbate
    Ranch Hand
    Posts: 30
    Spring Java Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Paul Clapham wrote:

    Pablo Abbate wrote:We are not discussing best practices, he wants to know what can he do with JSP ...



    But this is not some game where the task is to identify as many different ways to use a JSP as possible. The poster wants to learn about JSP, presumably so that he or she can use it to write web applications. Given that, the responsible thing is to identify best practices before the poster starts learning the less-than-best practices which are so lamentably common.



    I disagree with you. We're not discussing your ironic "game". He don't know nothing about JSP, so a very simple advise is to think about it as a mixture between java, jsp tags, html tags. I don't know if you have experience teaching, but you should start using what the people already know in order to create new concepts.

    for me the best it's start explaining what you CAN do, and then, what is the best.
     
    Paul Clapham
    Sheriff
    Posts: 27235
    87
    Eclipse IDE Firefox Browser MySQL Database
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Yes, I find the results of that type of teaching very depressing. All of the certification exams which you see discussed around the Ranch seem to be based on examples of really bad programming techniques, and the goal is to figure out what they are doing. And then you see people using those horrible examples as the basis for what they do in real-life programming. Because that's all they know after studying six months for the exam.

    So if you wanted to say that JSP was HTML mixed in with special tags, I wouldn't object. And neither would you, I think, because people are familiar with the concept of HTML being built from tags. But it isn't necessary to mention Java at all in there if you're going to go on and tell people "but you shouldn't actually use Java here". That just makes things more complicated for the learner.
     
    Bear Bibeault
    Sheriff
    Posts: 67645
    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

    Pablo Abbate wrote:for me the best it's start explaining what you CAN do, and then, what is the best.


    I could not disagree more. Learning bad practices and bad habits from the start creates problems that are hard to unlearn. Learning how to do things right from the outset is the best approach.

    Moreover, CodeRanch is a learning site. It is not a site to figure out how to do things quickly but poorly. Emphasizing best current practices from the outset is the best way to learn how to do things correctly, not just get crap out the door quickly.

    If you do not agree, then CodeRanch might not be the best site for you.
     
    Nandita Tiwari
    Ranch Hand
    Posts: 77
    Netbeans IDE Oracle Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    So Finally I should make an HTML page then a servlet and connect this servlet to DB?? I don't need to use JSP. M I right here?
     
    Bear Bibeault
    Sheriff
    Posts: 67645
    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

    Noopur Kore wrote:So Finally I should make an HTML page then a servlet and connect this servlet to DB?? I don't need to use JSP. M I right here?


    Well, no. How are you going to get dynamic values into the HTML without JSP? JSP is the template from which with the HTML is created.
     
    Nandita Tiwari
    Ranch Hand
    Posts: 77
    Netbeans IDE Oracle Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Okay, So I need to make JSP and HTML for my frontend and middleware as Servlet and DB connection, right?
    Do I need any servers? I heard we need tom-cat server or glass-fish server to make web applications. If so, How do I incorporate them in my project?
     
    Bear Bibeault
    Sheriff
    Posts: 67645
    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
    Either server comes with documentation on how to set it up.
     
    pie. 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