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.
Next: Run the web application in the Eclipse environment >>
More Java Articles
More By Gangyi