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!
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!
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?
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..
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 displayingthe 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.
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..
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!
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?
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..
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 .
Post by:autobot
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