Академический Документы
Профессиональный Документы
Культура Документы
JSP
JSP
<%code%>
The code is inserted into the servlet's service method
This construction is called a scriptlet
<%!declarations%>
The declarations are inserted into the servlet class, not into a
method
Scriptlets
Directives
JSP
<%@page contentType="text/html" %>
<html>
<body>
<%!
int cnt=0;
private int getCount(){
//increment cnt and return the value
JSP
cnt++;
return cnt;
}
%>
<p>Values of Cnt are:</p>
<p><%=getCount()%></p>
<p><%=getCount()%></p>
JSP
<p><%=getCount()%></p>
<p><%=getCount()%></p>
<p><%=getCount()%></p>
<p><%=getCount()%></p>
</body>
</html>
<%= new java.util.Date() %>
JSP
<html>
<head>
<title>Enter your name</title>
</head>
<body>
<p> </p>
<form method="POST"
action="showname.jsp">
JSP
<p><font color="#800000" size="5">Enter
your name:</font><input type="text"
name="username" size="20"></p>
<p><input type="submit" value="Submit"
name="B1"></p>
</form>
</body>
</html>
JSP
request.getParameter("username");
JSP
Here is the code of "showname.jsp" file:
<%@page contentType="text/html" %>
<html>
<body>
<p><font size="6">Welcome : <
%=request.getParameter("username")
%></font></p>
</body>
</html>
JSP
JSP in XML
XML: <jsp:expression>expression</jsp:expression>
HTML: <% code %>
XML: <jsp:scriptlet>code</jsp:scriptlet>
HTML: <%! declarations %>
XML: <jsp:declaration>declarations</jsp:declaration>
HTML: <%@ include file=URL %>
XML: <jsp:directive.include file="URL"/>
16