1 / 55

Eclipse Web Tools

Session Number: D14. Eclipse Web Tools. Arthur Ryman, ryman@ca.ibm.com Chuck Brigham, cbridgha@us.ibm.com. Objectives. You will learn about the structure of the Eclipse Web Tools Platform (WTP) project You will be given an overview the WTP release roadmap

vidar
Download Presentation

Eclipse Web Tools

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Session Number: D14 Eclipse Web Tools Arthur Ryman, ryman@ca.ibm.com Chuck Brigham, cbridgha@us.ibm.com

  2. Objectives • You will learn about the structure of the Eclipse Web Tools Platform (WTP) project • You will be given an overview the WTP release roadmap • You will be shown a Quick Tour demonstration that touches on many of the key functional components of WTP • After this session you will be able to use WTP and attend further sessions that go into more detail about J2EE and Web services tools Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both. Other company, product, or service names may be trademarks or service marks of others.

  3. Abstract The Web Tools Platform (WTP) Project extends Eclipse with tools for developing Java Web Applications. The Web Standard Tools subproject contains tools for HTML, CSS, JavaScript, XML, Web Services and Data access. The J2EE Standard Tools subproject contains tools for servlets, JSP, JSF, EJB, and Java Web Services. The WTP project was initiated by IBM and seeded with core components of Rational Application Developer (RAD) V6. WTP will be the basis for the next major release of RAD. This session gives and overview of the project, explains its structure and goals, and demonstrates the tools.

  4. Outline • Project Overview • Release Roadmap • New in WTP 1.0 • New in WTP 1.5 • Beyond Callisto • Quick Tour Demo • Dynamic Web Projects • JSPs and Servlet • Database Access • Web Services

  5. Project Overview • WTP provides tools for Java Web application development • Tools for application developers • Platform for tool developers • Subprojects focus on open standards • Web Standard Tools – IETF, W3C, OASIS, WS-I, ANSI, etc • J2EE Standard Tools – JCP • IBM contributed core components of Rational Application Developer V6.0 and remains the largest contributor • BEA, Oracle, Sybase and many others participate in WTP development • IBM will adopt WTP 1.5 in Rational Application Developer V7.0

  6. WTP Subprojects and Open Standards WST HTML, XML, XSLT, CSS, JS, WSDL, SOAP, UDDI JST Servlet, JSP,EJB, JAX-RPC,JDBC, JAXP, JSF, J2EE IETFW3COASISWS-IECMAANSI De Jure Standards JCP SQL JDO Web Technologies Java Technologies XUL PHP Struts Hibernate Spring MozillaZend Apache ObjectWeb SourceForge De Facto Standards

  7. Web Standard Tools (WST) • Web Projects • Web server control • Structured Source Editing Framework • HTML, JavaScript, CSS • XML, DTD, XSD • Web services (WSDL, WS-I) • SQL, relational database access

  8. J2EE Standard Tools (JST) • J2EE Projects • J2EE server control • Servlets • JSP • EJB • Java Web services (JAX-RPC)

  9. Release Roadmap • WTP 0.7, July 2005 – Tools for Application Developers • 0.7.1 September, 2005 • WTP 1.0, December 2005 – Platform for Tool Developers • 1.0.1 February, 2006 • 1.0.2 April, 2006 • 1.0.3 TDB • WTP 1.5, June 2006 – Callisto Simultaneous Release • 1.5.1 TBD • 1.5.2 TBD • WTP 2.0, June 2007 – Web 2.0, Java EE 5

  10. New in WTP 1.0 • First wave of Platform APIs • Component descriptors/scanners • Initial Feature definitions • Project Facets • External server adapters and runtimes installed via Update Manager • More supported servers • Adopter Hot List • Improved Help • Improved Scalability • Lots of other bug fixes and enhancements!

  11. New in WTP 1.5 (Callisto) • Initial steps towards Java EE 5 • JSF Tools Incubator • Dali EJB 3.0 Persistence Tools • Glassfish server adapter hosted at java.net • Components moved to Eclipse Platform: • Common Navigator (Project Explorer) • Tabbed Property View • More Platform APIs • Adopter Usage/Breakage Scans • XML based Help – DITA • Lots of other bug fixes and enhancements!

  12. JSF Tools Incubator Project • Led by Oracle with contributions from Sybase and IBM • JSF-JSP page source editor • application configuration (faces-config.xml) source/graphical editor • JSF library registry

  13. Dali EJB ORM Incubator Project • Support for development of Java Persistence API (JPA) persistent Entities within Eclipse • Leverage and integrate into existing Eclipse platform and projects, esp. WTP, DTP

  14. Design Time Mapping Validation ADDRESS P_CODE ID CITY COUNTRY Default mapping won’t work!

  15. WTP 2.0 - Beyond Callisto • DTP Adoption • Remove Data Tools • Java EE 5 support • Update J2EE models and API • Graduation of JSF and Dali projects • AJAX Tools Framework Incubator • Improved JavaScript editor and new debugger • Collaboration with PHP Tools Project • Improved Apache Web server support • Collaboration with SOA Tools Project • Improved WS-* support • Continued definition of Platform APIs and Features • Focus on adopters

  16. Quick Tour of Eclipse WTP

  17. WTP Quick Tour Iterations • Configure an application server, create a Web application, develop a simple JavaServerTM Pages (JSP) document that prints a greeting, and run it on the server. • Add a login JSP, write Java scriptlets to display the user name, create a Java servlet that controls the application page flow, and debug the servlet and JSPs. • Create a database to store user information, develop an SQL query to access it, and add Java Database Connectivity (JDBC) calls to your servlet to invoke the query and retrieve the user information. • Deploy the database query as a Web service, generate a JSP test client that invokes the Web service, and monitor the Simple Object Access Protocol (SOAP) message traffic.For the most benefit, download a recent WTP release and follow along!

  18. Iteration 1: J2EE Web Applications • In iteration 1 we will configure our development environment, and create a dynamic Web application • Tasks: • Configure an application server • Create a Dynamic Web application project • Develop a simple JavaServer Pages (JSP) document that prints a greeting • Run the JSP on the server

  19. Configure an Application Server • An application server is needed to run our Java Web application • Window > Preference > Server preferences > Installed Runtimes • Click Add. Specify the location of Tomcat.You must specify a JDK so your JSPs will compile.

  20. Create a Web Application Project • The project will contain all of our Web artifacts such as JSPs, servlets • Select File > New > Project … > Web> Dynamic Web Project wizard. • Name the project Project1. • Associate Tomcat with Project1. • Click Finish.

  21. Develop a Simple JSP that Prints a Greeting • The JSP will display “Hello, World” in a client’s Web browser • Right click on Project1’s WebContent folder and select New->JSP. • Name the JSP hello-world.jsp. • Click Next. Select JSP with html markup. • Click Finish. • Change the title and add body contents for “Hello, world.”

  22. hello-world.jsp

  23. Run the JSP on the Server • To make use of the JSP it must be run on a server, in our case Tomcat • Right click on hello-world.jsp and select Run As > Run on Server. • Tomcat starts up and displays theJSP.

  24. Iteration 1 Summary • We configured Tomcat to act as our application server • We created a Web application project • We developed a simple JSP that prints “Hello, world” in a browser • We ran the JSP on the Tomcat server

  25. Iteration 2: Servlets and Scriptlets • In iteration 1 we created a JSP that had static content • In iteration 2 we will add dynamic content Tasks: • Add a Java Scriptlet to a JSP • Debug a JSP • Create a Servlet • Debug a Servlet

  26. Add a Java Scriptlet to a JSP • Scriptlets allow us to add Java code to a JSP that will get executed on the server • Add the following scriptlet to the JSP’s body: <% String person = "?"; String user = request.getParameter("user"); if (user != null) person = user; %> Welcome to WTP, <%= person %>! • Select Run As->Run on Server • Provide the name by appending ?user=EclipseCon

  27. hello-world.jsp?user=EclipseCon

  28. Debug a JSP • Debugging a JSP allows us to step through the JSP’s execution path • Set a break point on the lineString user = request.getParameter("user");by double clicking in the margin. • Right click on hello-world.jsp and select Debug As > Debug on Server. Tomcat will now restart in debug mode. • Select to resume execution. • Change the user to Alice. Notice the variables view shows the changed value.

  29. Debug hello-world.jsp

  30. Create a Servlet • JSPs should only contain presentation logic. • Application logic should be performed by servlets. • We will now add a login JSP and a servlet to handle the login request.

  31. Create a Login JSP • The login JSP will submit information to a servlet using a form • Create login-user.jsp the same way we created hello-world.jsp. • Add the following content to the JSP: <head> <title>Login User</title></head><body> <h1>Login User</h1> <% String error_message = ""; Object error = request.getAttribute("error"); if (error != null) error_message = error.toString(); %> <form action="HelloServlet"> <table cellspacing="4"> <tr> <td>Enter your user name:</td> <td><input name="user" type="text" size="20"></td> <td style="color: red"><%= error_message %></td> </tr> <tr> <td></td> <td><input type="submit" value="Login"></td> <td></td> </tr> </table> </form></body>

  32. Create a Servlet • The servlet will take the input from our JSP, perform some logic, and return either the login JSP or the hello world JSP • Right click on Project1 and select New->Servlet. • Specify the package name org.eclipsecon and the name HelloServlet. • Click Next. Accept the default name and mapping. • Click Finish. The wizard creates the Servlet skeleton.

  33. Add Logic to the Servlet • Because we specified GET in login-user.jsp we will implement doGet() • Add the following implementation to the doGet method: protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String url; String user = request.getParameter("user"); if (user == null || user.length() == 0) { url = "/login-user.jsp"; request.setAttribute("error", "User name must not be empty."); } else { url = "/hello-world.jsp"; } ServletContext context = getServletContext(); RequestDispatcher dispatcher = context.getRequestDispatcher(url); dispatcher.forward(request, response); }

  34. Run the Updated Application • Right click on login-user.jsp and select Run As->Run on Server

  35. Debug a Servlet • Debugging a servlet is very similar to debugging a Java class • Set a breakpoint in HelloServlet on the lineString user = request.getParameter("user");by double clicking in the margin. • Right click on HelloServlet.java and select Debug As->Debug on Server. • Select to resume execution. • Try changing the name and watch the execution path.

  36. Iteration 2 Summary • We made our JSP dynamic by adding a Java Scriptlet • We debugged our JSP on the server • We created a login JSP and a servlet to handle login requests • We debugged the servlet on the server

  37. Iteration 3: Database Access • In iteration 2 we created a dynamic Web application • In iteration 3 we will add a data layer to our Web application Tasks: • Connect to a Database • Execute SQL Statements • Add Database Access to our Web Application

  38. Show the Database Views • WTP provides two views that assist in working with databases. We need to show these views before proceeding. • Click on Window > Show View > Other… • Select the Database Explorer and Data Output views and click OK.

  39. Connect to a Database • Before working with a database we must first connect to it. • Right click in the Database Explorer and select New Connection… • Select Derby 10.1. • Enter a convenient location for the database such as C:\Project1db • Enter the location of derby.jar. It’s located in the plugins dir in org.apache.derby.core. • Click Test Connection. • If the connection test was successful, click Finish.

  40. Execute SQL Statements • We will now populate our database by executing SQL statements. • Open the SQL Scrapbook by clicking the button in the Database Explorer, selecting the Project1db, and enter a name of project1sql.sqlpage. • Enter the following statements into the editor. (You can replace a name with your own. • Select each statement individually, right click on it and select Run SQL. • Results are shown in the Data Output view. CREATE TABLE WEB1.LOGIN (USERID CHAR(8) NOT NULL, FULLNAME CHAR(20), PRIMARY KEY(USERID)) INSERT INTO WEB1.LOGIN (USERID, FULLNAME) VALUES ('dai','Naci Dai') INSERT INTO WEB1.LOGIN (USERID, FULLNAME) VALUES ('mandel','Lawrence Mandel') INSERT INTO WEB1.LOGIN (USERID, FULLNAME) VALUES ('ryman','Arthur Ryman') SELECT * FROM WEB1.LOGIN ORDER BY FULLNAME SELECT FULLNAME FROM WEB1.LOGIN WHERE USERID = 'ryman'

  41. Disconnect from the Database • Derby only supports a connection to a given database from one process – we need to disconnect before using the database in our Web application • Right click on the Project1db in the Database Explorer and select Disconnect.

  42. Add Database Access to our Web Application • We will now update our Web application to retrieve user names from the database we created • There are 4 tasks to perform: • Add the Derby library to our Web application • Create a class that will access the database • Update our Servlet to access the user name from the database class • Update our hello world JSP to display the user name

  43. Add the Derby Library to our Web Application • Our application needs access to the Derby libraries in order to access a Derby database • Copy derby.jar to WEB-INF/lib • note: While this method works fine for a single application, if multiple applications need access to a Derby database a shared copy of Derby must be used.

  44. Create a Class that will Access the Database • The class will contain all the logic to access the database • Create a new class named Database.java in the same package as HelloServlet.java. public class Database { public String lookupFullname(String userid) throws SQLException { Connection connection = null; PreparedStatement statement = null; ResultSet resultset = null; String fullname = ""; try { Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); connection = DriverManager.getConnection("jdbc:derby:C:\\{Project1db"); String QUERY = "SELECT FULLNAME FROM WEB1.LOGIN WHERE USERID = ?“; statement = connection.prepareStatement(QUERY); statement.setString(1, userid); resultset = statement.executeQuery(); if (resultset.next()) fullname = resultset.getString("FULLNAME").trim(); } catch (Exception e) { e.printStackTrace(); } finally { if (resultset != null) resultset.close(); if (statement != null) statement.close(); if (connection != null) connection.close(); } return fullname; } }

  45. Update Our Servlet to use the Database class • The Servlet will now access the user name from the database • Update the doGet method of HelloServlet.java to use Database.java. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String url = "/hello-world.jsp"; String user = request.getParameter("user"); if (user == null || user.length() == 0) { url = "/login-user.jsp"; request.setAttribute("error", "User name must not be empty."); } else { try { String fullname = new Database().lookupFullname(user); request.setAttribute("fullname", fullname); } catch (SQLException e) { e.printStackTrace(); } } ServletContext context = getServletContext(); RequestDispatcher dispatcher = context.getRequestDispatcher(url); dispatcher.forward(request, response); }

  46. Update JSP to Display the User Name • The JSP needs to be updated to use fullname. • Update the hello-world.jsp to retrieve the value of the fullname parameter and use it instead of the user parameter if it has been specified by changing the Scriptlet as follows:<% String person = "?"; String user = request.getParameter("user"); if (user != null) person = user; Object fullname = request.getAttribute("fullname"); if (fullname != null) person = fullname.toString(); %>

  47. Run the Updated Web Application • Run login-user.jsp on the server. • Try entering a user id. The resulting page now displays the name instead of the user id.

  48. Iteration 3 Summary • We connected to a Derby database • We executed SQL statements to populate the database and view the values we added • We added database access to our Web application enabling the application to display the user name instead of the user id.

  49. Iteration 4: Web Services • In iteration 3 we created a data layer for our Web application • In iteration 4 we will expose that data through a Web service Tasks: • Deploy a Web service • Test a Web service with a test client • Monitor SOAP messages

  50. Deploy a Web Service • We will create a Web service using the bottom-up approach to expose our Database.java class. • Right click on Database.java and select Web Services > Create Web service. • Check the following items: • Start Web service in Web project • Generate a Proxy • Test the Web service • Monitor the Web service • Click Finish.

More Related