Home arrow Java arrow Page 2 - Finishing the Project: Java Web Development in Eclipse and Tomcat
JAVA

Finishing the Project: Java Web Development in Eclipse and Tomcat


Last week, I introduced you to some of the fundamental concepts you need for working with Java web components. For this project we'll be working with JSP and servlets. I walked you through getting the appropriate downloads installed and setting up your work space. We stopped after just creating the web project. In this part, we will add our content, including HTML, JSP, and servlets.

Author Info:
By: Gangyi
Rating: 5 stars5 stars5 stars5 stars5 stars / 24
May 29, 2007
TABLE OF CONTENTS:
  1. · Finishing the Project: Java Web Development in Eclipse and Tomcat
  2. · Create welcome.jsp
  3. · Run the web application in the Eclipse environment
  4. · What just happened?

print this article
SEARCH DEVARTICLES

Finishing the Project: Java Web Development in Eclipse and Tomcat - Create welcome.jsp
(Page 2 of 4 )

Creating a JSP page requires taking similar steps as you did for creating an HTML file except for selecting JSP rather than HTML from the context menu. The text of welcome.jsp file is below.

<html>
<head>
  <title>Welcome page</title>
</head>
<body>
  <pre>
  <%

 
String secreteUser = "user";
 
String secretePass = "pass";
 
String username = request.getParameter("username");
 
String password = request.getParameter("password");
 
%>
 
<%if(!(username.equals(secreteUser) || password.equals(secretePass))) {%>
   
Wrong username / password
 
<%} else {%>
   
Welcome aboard <%=username%>!
 
<%}%> '
 
</pre>
</body>
</html>

You can see that JSP is a mixture of HTML elements and Dynamic Java code.

Everything between the start tag <%  and end tag %> is JSP code, in other words, Java code.

A JSP page may contain the following components:

  • static HTML
  • JSP directives such as the include directive
  • JSP scripting elements and variables
  • JSP actions
  • custom tags

In this simple JSP, only JSP scripting elements and variables are used.

You might ask where the request comes from. The request is one of six JSP Implicit Objects: out, page, pageContext, request, session, and config. They can be references from your JSP code directly.

The code between and features scriptlets just like your Java Code in a method.

<%=username%> is an expression.


blog comments powered by Disqus
JAVA ARTICLES

- Java Too Insecure, Says Microsoft Researcher
- Google Beats Oracle in Java Ruling
- Deploying Multiple Java Applets as One
- Deploying Java Applets
- Understanding Deployment Frameworks
- Database Programming in Java Using JDBC
- Extension Interfaces and SAX
- Entities, Handlers and SAX
- Advanced SAX
- Conversions and Java Print Streams
- Formatters and Java Print Streams
- Java Print Streams
- Wildcards, Arrays, and Generics in Java
- Wildcards and Generic Methods in Java
- Finishing the Project: Java Web Development ...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials