• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlets using JDBC

 
anubha goel
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic