aspose file tools*
The moose likes Servlets and the fly likes servlets using JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlets using JDBC" Watch "servlets using JDBC" New topic
Author

servlets using JDBC

anubha goel
Greenhorn

Joined: Jul 06, 2007
Posts: 22
Hi,
I am trying to make a servlet program using JDBC.I am not getting how to refer to a particular button.My source code is:

------------------------------------------------------
And the corresponding HTML file is:

<html>
<form action="sam" method="Post">
name    <input type=text name=name><BR><BR>
age      <input type=text name=age><BR><BR>
class    <input type=text name=clas><BR><BR>
id    <input type=text name=id><BR><BR>

<BR>
<input type=submit value=insert>  
<input type=submit value=select>  
</form>
</html>
-----------------------------------------------
I am able to compile it but when i run the Html file n press enter it displays page cannot be displayed...
Please help me out...
Thanks in Advance.

Regards,
Anubha.



[BPSouther: Added code tags]
[ August 07, 2007: Message edited by: Ben Souther ]
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
There might be missing link , but this is what I would have done.

1> Move the database code out of servlet and unit test that to ensure that fetching of records from database is working fine.

2> Call the above code from within the servlet.

3> Check for the mapping of the servlet in web.xml to ensure that click on button on HTML page is invoking the servlets doGet method.

Just for you information , keep the driver library in WEB-INF's lib folder.
Hope this helps,


Rahul Bhattacharjee
LinkedIn - Blog
Amol Nayak
Ranch Hand

Joined: Oct 26, 2006
Posts: 218
Is the url /sam mapped to the servlet in your web.xml.

Can post the web.xml as well?

when you press the submit you should be getting something like (assuming its
running locally and on tomcat)

http://localhost:8080/<appname>/sam
anubha goel
Greenhorn

Joined: Jul 06, 2007
Posts: 22
Hi,
i have followed all the steps as mentioned by Rahul.everything is working fine tha way.my web.xml file is:


<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtds/web-app_2_3.dtd">

<web-app>
<servlet>
<servlet-name>/sam</servlet-name>
<servlet-class>sam</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>/sam</servlet-name>
<url-pattern>/sam</url-pattern>
</servlet-mapping>
</web-app>
--------------------------------------
Thanks & Regards,
Anubha.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: servlets using JDBC