class - How can I break down this servlet.java into more classes? -


i'm using gae, runs jetty, , java. have working servlet in 1 monolithic java file. start breaking down different classes.

at point want place of code class , call idea of generating different webpages in different classes depending on input.

right now, in /servlet.java, have:

package webapp         public class servlet extends httpservlet {            public void doget(httpservletrequest req, httpservletresponse resp) throws ioexception {            ...            try {                temp.process(root, resp.getwriter());            } catch (templateexception e) {                throw new ioexception("error while processing freemarker template", e);            }          } 

when try create new class with:

public classa {  public void generatepagea() {      public void doget(httpservletrequest req, httpservletresponse resp) throws ioexception {         ...         resp.setcontenttype("text/html; charset=utf-8");          try {         temp.process(root, resp.getwriter());     } catch (templateexception e) {         throw new ioexception("error while processing freemarker template", e);     }       }   } 

then in servlet.java try call function in classa

classa.doget(); 

but syntax error requesting identifiers after tokens.

for calling classa.doget(); need make static,

public classa {      public static void doget(httpservletrequest req, httpservletresponse resp) throws ioexception {         resp.setcontenttype("text/html; charset=utf-8");         try {             temp.process(root, resp.getwriter());         } catch (templateexception e) {            throw new ioexception("error while processing freemarker template", e);         }      } } 

you have pass arguments :

package webapp public class servlet extends httpservlet {     public void doget(httpservletrequest req, httpservletresponse resp) throws ioexception {         classa.doget(req,resp);     } } 

if want more informations post complete stack trace, can provide better support


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -