How to relate/connect Phonegap with my servlets?


i have created mobile survey html, css, javascript , servlets. trying incorporating whole mobile survey app. have managed put html, css , javascript files phonegap script files. looks same on mobiles , tablets. have issue - not submit file database. have been googling , should separate files ( dont know how/what mean separating files) know phonegap platform html, css , javascript. how should separate them?

 

this code in survey.html

 

<form id="myform" name="myform" method="post" action="formservlet" data-confirm="are sure want submit form now?">

..... more codes

 

and code in formservlet

 

@webservlet(urlpatterns = {"/formservlet"})

public class formservlet extends httpservlet {

 

     @suppresswarnings("empty-statement")

     protected void processrequest(httpservletrequest request, httpservletresponse response)

             throws servletexception, ioexception {

         response.setcontenttype("text/html;charset=utf-8");

       

         try {

            string r_ipaddress = request.getparameter("ip"); 

            string r_firstname = request.getparameter("firstname"); 

            string r_lastname = request.getparameter("lastname");

          ........................... mode codes

 

how survey.html talk database?

can still use servlet?

1. separation means should implementing type of mvc architecture. in case, have client (the app), process (the servlet) , database.

2. servlet should able receive post data , return string or json object app. should validate data , use database api store data if valid.

3. app should able use xhr (ajax) post data , receive response. upon error message servlet, should redisplay form data , error message, otherwise should continue ui dialog user.

 

one characteristic should not use 'action' attribute of 'form' element. instead, catch submit event of form, dismiss default action, build ajax (xhr) request , send full url of web service (which servlet).

 

make sure include whitelist plugin npm , whitelist rule external server on 'access intent'. see whitelist plugin's documentation.

 

before sending data servlet, validate data client side. need additional ajax request receive validation rules server, too.

 

find tutorial , examples using google: "tutorial javascript ajax servlet" or similar.



More discussions in PhoneGap


adobe

Comments

Popular posts from this blog

Illustrator CS6 Ocurrío un error E/S en el archivo.

Why is os_ViewContainer running?

Animate - problem with duplicating scripts after loop