user1545253
user1545253

Reputation: 3

submit button in JSP does not trigger doPost in Servlet

I have a form that lives in a .jsp file (yarntree.jsp). The form is populated when a user clicks on a google map, via a javascript function that lives in an external js file (map.java). I want to send that data to an sql database, and then have the original jsp page redisplay with the form now empty. The code for that lives in a .java file (YarnTreeServlet.java). The mappings are in web.xml

I am using V3 of the maps api, along with appengine.

Web app can be seen here:

Problem: the submit button does not result in anything being sent to the doPost method.

I have added some code in the javascript to write out the values to the console and those are populated correctly. I have checked the query, and it would insert correctly if doPost worked. I have spent hours on this, and am at loss. Is there some reason why I cannot access the values that are in the form once they have populated? I am aware that the servlet mapping is likely part of the problem, but I have tried a number of variations with no success. At this point I am unable to tell if the problem is in the js, the jsp, the form, the doPost, or the web.xml. Any help would be appreciated.

Upvotes: 0

Views: 2758

Answers (2)

user1545253
user1545253

Reputation: 3

So, it turns out that I needed to do 'doGet' and not doPost. From what I understand, this is because I am needing the value of the parameters that are being processed via jquery as a result of a onclick even in javascript.

Thank you for all your help.

Upvotes: 0

KV Prajapati
KV Prajapati

Reputation: 94645

Correct me if I'm wrong but I can't see the servlet url in <form> tag.

  <form id="createMarkerForm" 
        method="post" 
        accept-charset="utf-8" 
        action="servletUrl">

and doPost is not override properly.

 @Override
 public void doPost(HttpServletRequest req, 
                    HttpServletResponse resp) 
                        throws ServletException, IOException{    
 }  

Upvotes: 1

Related Questions