XML usage in Web Application
How to enable Auto-Refresh in JSP Pages and Servlet
In servlets we use response Headers to achieve Auto-Refresh
response.setIntHeader("Refresh",3);
In JSP pages we use META tags to achieve Auto-Refresh
META HTTP-EQUIV="Refresh"
CONTENT="5;URL=http://localhost:8080/SecurityCheck/Test1.html">
// URL=http://localhost:8080/SecurityCheck/Test1.html --> NOT Mandatory.
5 - Indicates the number of seconds after which the Page should refresh.
Auto servlet refresh
Tomcat Adminstration and Tomcat Manager
Entries that are to be made in "tomcat-users.xml" to facilitate access to Tomcat Manager and Admin
role rolename="admin"/>
role rolename="manager"/>
user username="vishnu" password="vishnu" roles="admin,manager"/>
username and password attribute values in "user" tag are user-defined(Can be anything)
Simple and Classic Tags
Learn about it here and here
Can we place a JSP file inside WEB-INF
It is perfectly valid to put a JSP file inside the WEB-INF to prevent direct access to clients, in that case, it is only accessible via forwards/includes.
The problem is that the jsp inside WEB-INF folder cannot access resources like images,scripts etc.The specification doesn't suggest anything in this regard, it is upto the web-server whether to consider the jsp or not.
How to access such a resource
Why JSP can't implement interface?
Default Login Form
FORM action = "so" method = "post">
Name: INPUT type = "text" name = "username" />
Password: INPUT type = "password" name = "password" />
INPUT type = "submit" value = "submit" />
/FORM>
Either action attribute has to be fully qualified name including the application name and path (or) only path without any slash at the beginning.
Correct.
1. action="/ApplicationName/so"
2. action="so"
3. action="so/someExtraPath"
InCorrect
1. action="/so"
From where jspInit() is called ?
Where to place the tld files
Referer
How to find the request URL? For example if the request is made from
"http://localhost:8080/SecurityCheck/JspOne.jsp " this url, how to get it in the servlet code?
StringBuffer buffer = request.getRequestURL();
String str = new String(buffer);
System.out.println("RequestURL()" + str);
Is there a way to know from which page the request is coming. For example if I have a web application with 10 pages having a link to login page I like to know from which page the request to login page was made?
Referer:
It's an optional header field that contains the URL of the referring document.
The Referer field was designed for link backtracking and verification, not for authentication or session management.
request.getHeader("referer") will give you the source url
<%= request.getHeader("referer") %>
A very good article about referer is here
Take a look at this JavaRanch Thread to know why NOT to rely on referer Header.
page and pageContext implicit Objects
Default TLD File
?xml version="1.0" encoding="UTF-8"?>
taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd">
tlib-version>1.2 /tlib-version>
short-name>vis /short-name>
/taglib>
Default web.xml file
?xml version="1.0" encoding="UTF-8"?>
web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
/web-app>
JSTL - does it really make life simpler?