943,908 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1605
  • Java RSS
Mar 5th, 2008
0

java project database error

Expand Post »
i am doing an acadamic java project by using html, servlets.
in html form tag what is the url that i have to give in post attribute.
and i am using access as my database. it is giving that httpserver error
that given table is not found. will u please help me in sorting out this problem
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
madhusamala is offline Offline
8 posts
since Mar 2008
Mar 5th, 2008
0

Re: java project database error

In the form tag you must put the url in the 'action' attribute and in the 'method' attribute you put post or get:
Java Syntax (Toggle Plain Text)
  1. <form action="someurl" method="post">
  2. ...
  3. </form>
When you submit the form you send the information that are inside it to the given url
And I would suggest to use .jsp to build your pages not servlets
Last edited by javaAddict; Mar 5th, 2008 at 4:14 am.
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,259 posts
since Dec 2007
Mar 5th, 2008
0

Re: java project database error

<form action="url"mehtod="post"/>
but this url should identify which servlet to run at server side.

So,
in your web.xml, your

<servlet-mapping>
<servlet-name>somename</servlet-name>
<url-pattern>this pttern should identify your action url properly</url-pattern>
</servlet-mapping>

e.g.
if action="*.do" then
url patter should be

<url-pattern>*.do</url-pattern>
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Nilesh Pagar is offline Offline
9 posts
since Mar 2006
Mar 5th, 2008
0

Re: java project database error

well, that form tag you posted won't do as it's seriously malformed...
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Mar 5th, 2008
0

Re: java project database error

Click to Expand / Collapse  Quote originally posted by jwenting ...
well, that form tag you posted won't do as it's seriously malformed...

Well, then you will have a tough time in your project. Anyways it works for me.

Deploy below files in tomcat or any Servlet Container.

Directory structure should be like this.

Sample
---+WEB-INF
------+classes
----------+com
-------------+sample
------------------+Servlet.class
------------------+Servlet.java
------+lib
----------+servlet-api.jar
------+web.xml
---+index.html

1. index.html

<html>
<head></head>
<body>
<form action="sample.do" method="post">
<input type="submit" name="myName" ></input>
</form>
</body>
</html>

2. Servlet.java

package com.sample;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SampleServlet extends HttpServlet{

private static final long serialVersionUID = -8734960688756643493L;

protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
service(arg0, arg1);
}
protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
service(arg0, arg1);
}

protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<HTML>" +
"<HEAD>Sample</HEAD>" +
"<BODY>\n" +
"<H1>Hello World</H1>\n" +
"</BODY>" +
"</HTML>"); }

}


3. web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<display-name>Sample</display-name>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

<servlet>
<servlet-name>sample</servlet-name>
<servlet-class>com.sample.SampleServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>sample</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>


4. servlet-api.jar
download it from
http://www.mtholyoke.edu/courses/sro...ervlet-api.jar

Deploy this application and check if it works. If this also doesn't work then best luck.

And by the way "*.do" url is properly functioning in this sample web project.

And about the database error, it might not have been configured properly, provided if you are not doing anything logically or syntactically wrong in your code which connects D B.
Last edited by Nilesh Pagar; Mar 5th, 2008 at 2:12 pm.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Nilesh Pagar is offline Offline
9 posts
since Mar 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Separating parts of an object
Next Thread in Java Forum Timeline: cohort class compile errors





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC