Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

getting 404 and data not able to insert into database  RSS feed

 
tangara goh
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear expert,

I have a form where the data will be inserted into the database when the user hit submit.
But, I am getting 404 error and it says my dao.tutorDAOFactory and daoMySql.tutorDAOImpl never used.












 
Dave Tolls
Ranch Hand
Posts: 2551
27
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What URL is it trying to hit when you get the 404?

Also, you shouldn't be doing a generic "process" method for both GET and POST.
If you're adding data to the database it should just be a POST and either the GET does something else (retrieves data, for example), or returns a 404.
 
Tim Moores
Saloon Keeper
Posts: 3564
77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, the code is wide open to SQL insertion attacks. You should get up to speed on using PreparedStatement before using this code in a production setting.
 
tangara goh
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:What URL is it trying to hit when you get the 404?

Also, you shouldn't be doing a generic "process" method for both GET and POST.
If you're adding data to the database it should just be a POST and either the GET does something else (retrieves data, for example), or returns a 404.



The URL is :
http://localhost:8081/Hi5/addTutor

This is after I got rid of process and put everything under POST

I do not understand why the problem indicated that import daoMySQLtutorDAOImpl and import dao.tutorDAOFactory is never used.

Hope someone can point out anything wrong with the code.

Tks.

 
Swastik Dey
Rancher
Posts: 1784
14
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is addTutor?  Because the servlet mapping name appears to be tutorController?
 
Dave Tolls
Ranch Hand
Posts: 2551
27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is indicating that those imports aren't used?
Not that that is going to be your issue.

As Swastik says, that URL does not match the mapping in the class.
 
tangara goh
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swastik Dey wrote:What is addTutor?  Because the servlet mapping name appears to be tutorController?


Hi Swastik,

addTutor is an action that I want the servlet Controller to perform.  It is "mapped" to the jsp form.

Should I add a getPathServlet() in this case inside my servlet Controller ?

<div class="row">
<div class="col-md-8">
<h4>Tutor Registration</h4>
<form name="registerTutor" method="POST" action="addTutor" id="contactForm" novalidate>
 
tangara goh
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dave and Swastik,

I think I found the answer, I forgot to put in the context file name.  And now there is no 404 error.

/contextfilename/addTutor
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!