java - confused with the design of servlet -



java - confused with the design of servlet -

i want create servlet receive info in json format , store info in database. when send info servlet through http request, found connection table, create table, , store data. code create connection , table has done first time. not able come design of code create connection , table first time , store info rows rest of time

my code follows :-

public class master extends protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { handle(request, response); } private void handle(httpservletrequest req, httpservletresponse resp) { jsonobject jsonobject = null; if ( req.getmethod().equalsignorecase("post")) { seek { string jsonstring = extractjsonbody() /* code connection database create table store info */ } grab (exception e) { system.out.println("json in bad format"); } } }

you can utilize init method of servlet connection , table creation status check if table doesn't exist in database.

public void init(servletconfig config) throws servletexception { // store servletconfig object , log initialization super.init(config);`` // create database connection , table creation status if //table not exist in db }

java servlets web-applications

Comments

Popular posts from this blog

php - How to pass multiple values from url -

database - php search bar when I press submit with nothing in the search bar it shows all the data -

ios - How to load .png images from Documents folder of an app -