java - How to compile servlet on remote server? -


i want upload servlet file on remote apache tomcat server , want compile it. wanted know under directory should keep file , how compile it? should use putty? relatively new servlets. here servlet code:

import java.sql.connection; import java.sql.preparedstatement; import java.sql.drivermanager; import java.sql.resultset; import javax.servlet.annotation.webservlet; import javax.servlet.http.*;  @webservlet(name= "db-connect", urlpatterns="/db-connect") public class dbconnect extends httpservlet{  private connection con = null; private preparedstatement preparedstatement = null;   protected void doget(httpservletrequest request, httpservletresponse response) {     try     {         class.forname("com.mysql.jdbc.driver");         con = drivermanager.getconnection("jdbc:mysql://http://localhost:3307/abc?autoreconnect=true");          preparedstatement  = con.preparestatement("select * person");          resultset rs = preparedstatement.executequery();         while(rs.next())         {             string email = rs.getstring("email");             system.out.print(email);             system.out.println("in");         }      }     catch(exception e)     {      } } 

also need make changes web.xml?

answers 1 one:

  1. you cannot deploy servlet only, have pack war file deploy it. now, how pack in war file? either let ide you're using (see of corresponding ide you're using) or build project management tool such maven or ant you. propose start exporting war file ide. if you're using eclipse, made fast google , found this video can watch it(i haven't watched end end seems right).

  2. exporting web project war file, means servlet classes compiled , packed in it, there's no need compile them on server. if need compiled automatically when invoked, you'll need jsp compiled first time when invoked (again no efforts side).

  3. it not idea transporting war files manually server (with putty, remote desktop windows, etc.), because might someday need deploy on server not have remote access. tomcat can use tomcat deploy manager (for remote hosts) or ide (for localhost shown in video above). here's the documentation tomcat deployment. however, dir you're looking home think "webapps" in tomcat installation dir.
  4. for changes in web.xml... depends if you're using servlet version less 3.0, yes, should describe servlet in web.xml (the ides you, propose better first open web.xml , see whether servlet hasn't been described in there). if you're using servlet 3.0 have annotate servlet @webservlet annotation.

in order better understand servlets propose read this or this(depending on java ee version you're using) getting started on oracle's web site.

hope helps.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -