Looking for a Tutor Near You?

Post Learning Requirement »
x

Choose Country Code

x

Direction

x

Ask a Question

x

x
x
x
Hire a Tutor

How To Setup A J2EE Web Application. Continue

Loading...

Published in: Java And J2EE
1,487 Views

This tutorial is continuation of previous tutorial. This will guide to do complete hands learning.

Mr S / Kolkata

6 years of teaching experience

Qualification: B.Tech and 6+ years of experience of MNC IT Company.

Teaches: Computer, Electronics, IT, CSS Training, HTML Training, Web Development, Java And J2EE

Contact this Tutor
  1. How to Develop a J2EE application Continued.. Copy right to Supriya Mallick
  2. 1st Open web.xml, check list of welcome file list E.'/TestWorkspace/TestWebApp/WebContent/WE8-INF/web,xml web web.xml Context Params Filters Listeners Servlets session-config Mime Mappings welcome-file-list Error Pages JSP config Security Constraints login-config Security Roles Env Entries Services Resources n—cfinatinnc _rrr_, Tree SOUrce Welcome Files File Name indexhtml indax,htm indexjsp defaulthtml default,htm defaultjsp Copy right to Supriya Mallick Add... Remove... Edit... up Down 2
  3. Create index.jsp under WebContent folder web,xml index.jsp page contentType= "text/ html; " pageEncading= < ! DOCTYPE html "-//WSC//DTD 4.01 Transitional/ /EN" We1came to IJ2EE < / heady to ,J2EE Web Development tutorial . Normal • Normal Velcome to J2EE Web Development tutorial. html body Copy right to Supriya Mallick 3
  4. Folder structure look like this TestWebApp JRE System Library [jrE1.7101 Apache Tomcat v610 [Apache Tomcat v6101 build Ill WebContent e META-INF WEB-INF index.jsp Copy right to Supriya Mallick 4
  5. 1.Start the server. 2.Right click on server, add the project. 3.Right Click on Project and Click on Run on Server. indaxusp Welcome to J2EE http•„//localhost:8080/TestWebApp/ Welcome to J2EE Web Development tutorial. rift Copy right to Supriya Mallick 5
  6. Our application is up and running. Now we will add some server side response into the application, using Copy right to Supriya Mallick
  7. Open web.xml and add below servlet tags, after welcome-file-list tag. splay—name > < / s e et —mapping> Copy right to Supriya Mallick 7
  8. Create a HelloUserServlet0java, TestWebApp Deployment Descriptor: TestWebApp Java Resources: src (default package) Hel[oUserServlet.java Libraries t} build WebContent B META-INF , WEB-INF lib web,xml indax.jsp JavaScript Support Copy right to Supriya Mallick servlet 8
  9. It will be looks index.jsp Welcome to J2EE HelloUserServ[et.java Serviet implementation class HellcüaerServ1et public class HallaUserServ1ec extends Etc.pServ1ec private statio final long serial VersianLTZD IL; @see HttpServ1et#HttpServ1et public HellaüserServ1et ( ) { super (i ; // TODO Auto—generated canstructar stub like @see HttpServ1et#daGet (HttpServ1etRequest request, HttpServ1etRespanse response) protected void doGet (HttpServ1etRequest request, HttpServ1etRespanse response) throws ServietExcf // TODO Auto—generated methad stub super . doGat (request, reapanae) , Ésee HttpServ1et#dcPcst (HttpServ1etRequest request, HttpServ1etRespanse response) protected void doPaat (HttpServ1ecRequest request, HttpServ1etRespanae response) throws ServietExt // TODO Auto—generated methad stub super . daPoac (request, reapanaa) , Copy right to Supriya Mallick 9
  10. Now modify the index.jsp file. Will add a input form to take data from jsp and to send in server. Welcome to J2EE index.jsp pageEncading= "ISO—ESE -//W3C//DTD < ! html PUBLIC co J2EE < / heads HelloUserServlet.java 4.01 Transitional/ /EN" '"htt.p: //www.w3 . 'text/ html; We1came co C2EE Web Development cutarial
  11. Create output.jsp to display the server response or output of the program indexjsp Welcome to J2EE testELServletjava web.xrnl He[loUserServletjava output.jsp page language— "jäVä" cantentType= "text/ html; charset=iSC-aasg-1 ' pageEncading= "ISO-888 g -1 < ! DOCTYPE PUBLIC "-//W3C//DTD 4.01
  12. Now add following code in servlet doGet() method to handle the request. protected void daGet (HttpServ1etRequeat request, EccpServ1etReapanae response) throws Serv1ecExc // TODO Auto—generated methad stub null; String userNarre userName request . get Parameter ("userName " ) Serv1etCantext sc getServ1etCantext ( ) , RequestDispatcher requeacDiapatcher null; String outputStr null ; output.Str "+userName+", Welcome to ü2EE World b; request . setAttribute ( "output", output St: requestDispatcher—sc . getRequestDispatcher ( " / output . sp") , requestDispatcher. forward (request, response) Application is ready to build and deploy. Copy right to Supriya Mallick 12
  13. Save. Build and Restart the server. Right click on the application and Run on Server web.xml Welcome to J2EE indax.jsp http://localhost:8080/TestWebApp/ HelloUserServ[etjava outputJsp Welcome toJ2EE Welcome to J2EE Web Development tutorial. Enter you- name . Send Copy right to Supriya Mallick 13
  14. Enter name and Click on Send web,xml Welcome to J2EE indexjsp http".//localhost:8080/TestWebApp/ HelloUserServ[etjava outputjsp Welcome to J2EE Welcome to J2EE Web Development tutorial. Enter name Suprya Send: webxml lindexjsp Welcome to J2EE HE[loUserServletjava CO http'.//localhost:8080/TestWebApp/HelloUser?userName=Supriya&Send= Hi Welcome to J2EE World outputjsp Send Output of J2EE Application Copy right to Supriya Mallick 14
  15. Congrats on your 1st J2EE application. Thank you. Copy right to Supriya Mallick