wood burning stoves*
The moose likes JSP and the fly likes Getting started  with JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Getting started  with JSP" Watch "Getting started  with JSP" New topic
Author

Getting started with JSP

Noopur Kore
Ranch Hand

Joined: Aug 18, 2012
Posts: 77

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.
harshvardhan ojha
Ranch Hand

Joined: Jul 26, 2007
Posts: 157
    
    1

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.
Noopur Kore
Ranch Hand

Joined: Aug 18, 2012
Posts: 77

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

Joined: Jul 26, 2007
Posts: 157
    
    1

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.

Pablo Abbate
Ranch Hand

Joined: Aug 06, 2012
Posts: 30

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.


Nissi Group, Posicionamiento Web, Desarrollo de Software, DiseƱo Web
Blog , LinkedIn
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

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!


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

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.
    Noopur Kore
    Ranch Hand

    Joined: Aug 18, 2012
    Posts: 77

    where can I get a sample servlet code??
    Pablo Abbate
    Ranch Hand

    Joined: Aug 06, 2012
    Posts: 30

    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 ...
    Paul Clapham
    Bartender

    Joined: Oct 14, 2005
    Posts: 18656
        
        8

    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

    Joined: Aug 06, 2012
    Posts: 30

    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
    Bartender

    Joined: Oct 14, 2005
    Posts: 18656
        
        8

    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
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61420
        
      67

    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.
    Noopur Kore
    Ranch Hand

    Joined: Aug 18, 2012
    Posts: 77

    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
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61420
        
      67

    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.
    Noopur Kore
    Ranch Hand

    Joined: Aug 18, 2012
    Posts: 77

    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
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61420
        
      67

    Either server comes with documentation on how to set it up.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Getting started with JSP