Attempting to use JDBC along with html . . .

Discussion in 'OT Technology' started by DeeVoc, Apr 22, 2003.

  1. DeeVoc

    DeeVoc Heh.

    Joined:
    Aug 13, 2001
    Messages:
    33,124
    Likes Received:
    0
    Location:
    Brooklyn
    So basically what I want to be able to do is have it so that I have a webpage set up with embedded html that will take information filled out in forms and send it to a database via jdbc. I know it's possible but I can't find any examples like. If anyone could point me in the direction of anything where an html page is interacting with embedded html I'd really apppreciate it. Any tutorials or examples would be good. Thanks.
     
  2. DeeVoc

    DeeVoc Heh.

    Joined:
    Aug 13, 2001
    Messages:
    33,124
    Likes Received:
    0
    Location:
    Brooklyn
    I realize making an entire app using swing would be a straightforward way to do it, but if I could html I think it'd look a lot nicer have a definate advantage as far as ease of use.
     
  3. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    I can code up something quick. Give me a bit. Do you have MySQL and Tomcat?
     
  4. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    Ok, I'm done. I zipped up the entire project, so if you use JBuilder you can just unzip and open the .jpx project file.

    Flow:

    index.jsp takes two input variables. Once submitted, the ProcessForm servlet is invoked. It gets the two variables, prints them to the screen, creates a session setting each variable in session, and calling a method from the Database class. The setValues method from the Database takes userName and userPassword Strings. You'll need to add the SQL statement yourself, but hopefully you'll get what's going on in there. After the database call is finished and the session gets created, you get redirected to the results.jsp page where the values are gotten from session and displayed to the screen.

    Hope this helps. And let me know if something doesn't work right.

    http://www.compiledmonkey.com/cm/WebTutorial.zip

    *Edit* Also, normally you wouldn't do it this way. Having scriplets in the jsp is bad practice. I would normally use a JavaBean to handle any data being passed around. But for learning purposes, this should be fine.
     
  5. DeeVoc

    DeeVoc Heh.

    Joined:
    Aug 13, 2001
    Messages:
    33,124
    Likes Received:
    0
    Location:
    Brooklyn
    hrm, alright. I'm kind of at bay as to what's available to me on the class server. From what I'm looking at it looks like I'm going to have to bite the bullet and do it all using swing. Thanks for the example though, I'll try to code something up once I finish this project so I can get more familiar.
     
  6. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    Chris,

    Have you got Tomcat/Connectors working with Apache on your linux box?
     
  7. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    No, I've never tried to get that working. I've heard it's a bitch though.
     
  8. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    yeah, it is a bitch. I can get Tomcat running by itself, not hard at all.. but using the connectors to link up to apache is a pain in the ass. I'll be doing all that shit tonight over at this jobsite I've picked up. I'll let you know if all goes well ;)

    It seems that all the howto's i find are all out of date, or don't work with apache2 :mad:
     
  9. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    Yeah, a professor I've been working with is big into Unix and J2EE. The school uses JRun I believe, but they want to move to Apache/Tomcat and just drop EJBs. He said it took him awhile to get Apache and Tomcat working together. For my development purposes, I just run Tomcat on my laptop. I guess it lacks the security of Apache, but I'm not really sure. My apps deploy to WebLogic and other application servers fine. :dunno:
     
  10. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    hell, if it's just local, why even worry about security? And if it deploy's who cares.

    We wrote document controll software running jsp, and i'm trying to deploy it. My partner developed it in Oracle and on a Sun box which has some 3rd party connector that he bought and runs pretty seemlessly. So we're trying to deploy it at this client's network on a linux box. I was there freaking late last night. It doesn't help that the network card driver has a bug and the system keeps hanging on me :mad:
     
  11. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    Exactly.

    Sounds cool. I was actually going to work on something like that a few months ago, but other items came up with higher priority. Good luck with it.
     
  12. DeeVoc

    DeeVoc Heh.

    Joined:
    Aug 13, 2001
    Messages:
    33,124
    Likes Received:
    0
    Location:
    Brooklyn
    UPDATE: So my prof and TA are both working hard to fuck up whatever plan I start to work on. I start looking into JSP and it's not available on the class programming cluster, which I have to use. Then I say, "fuck it, I'll do it the hard way and do it all in swing", but no prof insists in class that we do it in a web interface as stated on the spec. It turns out that both apache and tomcat may be installed and working correctly on the server, but the TA is looking to it :o.

    So here's where I'm confused. If tomcat is workign correctly on the cluster can't I then begin to implement jsp pages? I'm thumbing through my thinking in java manual and that's what it's telling me. Just kinda confused here and my TA is still grasping english so he's not too much of a help. Thanks.


    CM - I really appreciate the example, but I don't use jbuilder. I mainly use Drjava or simple text editors. I'm trying to find the file(s) with the meat of the code but most of it just seems to be setup files that borland creats. What exactly should I be looking for?
     
  13. DeeVoc

    DeeVoc Heh.

    Joined:
    Aug 13, 2001
    Messages:
    33,124
    Likes Received:
    0
    Location:
    Brooklyn
    nevermind, found the important files. Thanks again. appreciate it.
     
  14. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    Honestly, when you get into larger projects you'll want something like JBuilder. Do yourself a favor and download the trial version. It sets up everything for you very well.

    "tomcat is workign correctly on the cluster can't I then begin to implement jsp pages?"

    Yup.
     
  15. VBGOD

    VBGOD Guest

    Very impressive...
     
  16. VBGOD

    VBGOD Guest

    Dumb question: J2SE or J2EE?
     
  17. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    J2SE with the Servlet and MySQL jars added to the project. ;)
     
  18. DeeVoc

    DeeVoc Heh.

    Joined:
    Aug 13, 2001
    Messages:
    33,124
    Likes Received:
    0
    Location:
    Brooklyn
    Okay, got tomcat installed on my account, but I'm just kind of figuring out how the hell to do everything now. There's no pub directory for my account so I'm trying to see how it's possible to display my jsp pages from a web browser.

    Also trying to figure out where I have to store my servlet code so the jsp pages can find and and tomcat can run it.
     
  19. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    Code:
    -webapps
      -app name
        -WEB-INF
          -classes
            -packages
          -lib
            servlet.jar
          web.xml
        index.jsp
    
     
  20. VBGOD

    VBGOD Guest

    Talk about that in some detail...

    Added as in installed (exe), or added via code Import blah.blah

    Also, I noticed one of the files had the following line within it.
    Code:
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
    What tool are you using to create this? I noticed the J2EE embedded in the link and it threw me off.
     
  21. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    First, you'd add the jar file to your WEB-INF/lib directory. Then you call the import statement like you said. Using JBuilder, you right click the project in the top left panel, click properties, click the req libs tab, then add any jar files you want to use. This method basically does what I mentioned in the first method, just through the IDE.

    Since Servlets are a part of J2EE, the web.xml is validated against a J2EE dtd. That line is an xml thing, not Java. ;)

    When you create a Servlet using the wizard in JBuilder, it creates your deployment descriptor (web.xml) and starts you off with...

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
    <web-app />
    
     
  22. VBGOD

    VBGOD Guest

    My friend is looking for a full copy of JBuilder, but has no money. :o
     
  23. DeeVoc

    DeeVoc Heh.

    Joined:
    Aug 13, 2001
    Messages:
    33,124
    Likes Received:
    0
    Location:
    Brooklyn
    So yeah as long as we're in my thread can either of you help me out with 2 questions I've got?

    Tomcat is in my account (on a unix server) and I've got it pointing to the right java directory and chmoddded it so it starts up and shuts down fine. So my questions are as follows

    1) Where do I place my .jsp and .java files for everything to work right? Or what must I change to have tomcat know where to look?

    2) How would I go about making my jsp files viewable by a browser since the only directory I'm provided with is my account directory. (no pub directory or anything). The account in on lets say foo.umd.edu and my account is say OT555. How would I go about doing it? Thanks.
     
  24. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    Yeah, the last time I helped you out you complained. :rant2:

    I'll just refer your friend to Kazaa or IRC. :o
     
  25. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    The JSP files go into the "root" directory of your project.

    Code:
    -webapps
      -app name
        -WEB-INF
          -classes
            -packages
          -lib
            servlet.jar
          web.xml
        index.jsp
    
    The .class files (servlets, beans, classes, etc.) go into the classes directory. I put packages because normally they are stored in a package.

    You'll have to ask your prof or whomever monitors the server. You can also get their help with your first question.
     

Share This Page