WEB-INF represents web app inner files, not expose to outside.
To prevent some jsp/html file on the server directly accessed by browsers from URL, we need to put all request sensitive jsp file under WEB-INF folder.
Put other jsp/html file outside WEB-INF, so browsers can directly access those files by URL.
Normally used forward action:
<jsp:forward page="/WEB-INF/login.jsp"></jsp:forward>
When the first time visiting jsp
- web server will convert A.jsp to A_jsp.java
- A_jsp.java will compile to A_jsp.class
So when the first time visit jsp, response time will be slow
9 objects
- out
- request
- response
- session
- application //servletContext
- pageContext //only this jsp scope
- exception
- page //this
- config //servletConfig
3 syntax
Command
Action
- <%@ page
contentType="text/html;charset=utf-8"
language="java"
import="java.util.*,java.net.*"
pageEncoding="utf-8"
session="true"
buffer="none|8k|"
autoFlash="true" //autoFlash to client when buffer full
isThreadSafe = "true"
errorPage="/error"
isErrorPage="false"
%>
We can use more than one page tag to make page nicer
<%@ page import="java.util.*" %>
<%@ page import="java.net.*" %> - <%@ include file="a.jsp" %> //static include
//combine two jsp file to one servlet - taglib
- <% java code %>
- <%=rs.getString("name")> //output string, no ; at the end
- <%! int count=10%> //servlet scope, member variable
<% int count=10; %> //function scope, local variable
<%! public int test(String a){
return a.length();
}%>
Action
- <jsp:forward page="/a.jsp"></jsp.forward> //forward to page
<jsp:forward page="/WEB-INF/login.jsp"></jsp:forward> - <jsp:include file=""></jsp:include> //dynamic include
//compile each jsp to different servlet first, then combine the output result
Comment
- <!-- Comments --> HTML comment, still output comment content
- <%-- Comments --%> JSP comment, does not output comment content to browser
No comments:
Post a Comment