Forums Register Login

Error loading the MySQL database table from a jsp

+Pie Number of slices to send: Send
I m new to programming and am working on the college project. I have MySQL 5.6.20, Eclipse Kepler and Apache Tomcat 7.0.54. I m trying to retrieve the whole table from MySQL schema into a jsp. All the possible things i can do, i have already tried, but none of them are helping. The following attachment contains the whole project. I have my sql connection code in Sample.java file, which i want to get working in Fetch.jsp on the Submit button click. But it shows the tomcat error as localhost:8080/Sample HTTP Status 404-/Sample ; type Status report; message /Sample; Description The requested resource is not available.

The help will be very much appreciated ASAP,please!






1
+Pie Number of slices to send: Send
In your web.xml why the / preceding Sample in servlet-class? remove the / .. and think it should have the fully qualified class name

Also the action property should be preceded by the webapplication context? like /YourWebAppName/Sample

hope this helps..
+Pie Number of slices to send: Send
Editing worked, i think. Removed / from servlet class and from action property. But this time the error is ClassNotFoundException which is called in the Sample.java class, meaning, the click event is NOW calling the class and then it is generating the exception. Suggest me, what to do NOW?
By the way, all the other fully qualified class names didn't work, just showed the Resource not available error!!
Help me on the exception error!
+Pie Number of slices to send: Send
Can you post your changes?
+Pie Number of slices to send: Send
Fetch.jsp



web.xml file



and the error message


1
+Pie Number of slices to send: Send
The class should be fully qualified.. like this..

<servlet-class>testusecase.Sample</servlet-class>
+Pie Number of slices to send: Send
 

Gamini Sirisena wrote:The class should be fully qualified.. like this..

<servlet-class>testusecase.Sample</servlet-class>




Yeah,that helped.After this i m not getting any errors but just a blank page.Should i make another table in jsp form to fill in with the database table column entries?
1
+Pie Number of slices to send: Send
Let's take this step by step..

You are doing this..

RequestDispatcher view = req.getRequestDispatcher("Fetch.jsp");
view.forward(req, resp);


comment those lines for now. Browse the web to find how to print stuff to the browser from your servlet. Once you are successful with printing a test message you can try printing all results from your query to the browser.
we'll talk after that..
+Pie Number of slices to send: Send
I have tried simple plain text like "Hello" and also, i commented the RequestDispatcher as you said to try getting the simple output as text.It is working with the help of PrintWriter object, at both the places, outside and inside the try{}. But the real problem i can't figure out is about displaying the table of the database schema. What exactly is it that i should do now? Sorry to be such a pain, but really need your help with this. It's a small,college project and it's already high time. Please Guide me the changes in the servlet ASAP.
1
+Pie Number of slices to send: Send
You want to display results from your database query right?

Now the way you printed the "Hello" you can print each value to the browser.
If you want to display the data in a HTML table then you have to write that to the browser as wel..

like..


+Pie Number of slices to send: Send
Sorry for the mess and trouble, but just minutes ago, i finally found a way out to print table after your advice to start search from how to print simple text. Now the problem is regarding the empty/Null values present in the database. jsp output isn't showing rest of the records if it finds a Null value in the first row itself.

Example: Scenario 1:Here the first record doesn't contain any value for 12th percentage in the database. So the rest of the records aren't showing up at all.
Scenario 2:The record with Serial no 8 have null value for Middle name into the database and from there the rest of the table show drops off.
This was just to verify that the problem i think is exactly about the null values.
Scenario 2 is after commenting the code. The output contains some personal information, so the snapshots aren't included.Sorry!
1
+Pie Number of slices to send: Send
with this
out.print((rs.getObject(1)).toString());

you are dereferencing g the object returned from the result set. Which would throw a null pointer Exception if it was null. I sugget you do.. for now.. which will handle the nulls.. (but will print null)

out.print((rs.getString(1)+""));

and aren't you seeing a null pointer stack trace in the console?
2
+Pie Number of slices to send: Send
Having HTML code inside servlet, is not good.. You should learn JSP, and use JSTL and EL to display the data you want in the view.
Since you are learning now, start learning the good habits..
+Pie Number of slices to send: Send
@GaminiSirisena, Sir, it sure works!! Thank you a lot.

@Prasad Krishnegowda...Thanks to you too. keeping that advice in mind, i am looking forward to learn it right away.
2
+Pie Number of slices to send: Send
Hi there,
There is a way to shorten your code and make it efficient. Try to use JSTL tag libraries. I use it all time and it works well.
+Pie Number of slices to send: Send
Hi, you have an HTML code inside your servlet, it's a bad practice You should learn JSP (JSP standared tag library) it will hep you to generate HTML code without using java code , also you can use JSTL inside your JSP pages try to learn this technologies, they wil help you .
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2597 times.
Similar Threads
Access the list of dtatabase records using jsp and servlets
Not able to evaluate Expression Language
Servlet and Jsp Communication Understanding
Prevent intermediate access to any jsp page
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:00:15.