1. Different HTTP status codes and their significance with examples?
There are 5 types of status codes
a) 1xx - Information
eg: 100 - Continue, 101 - Switching protocols
b) 2xx - Success
eg: 200 - OK
c) 3xx - Redirection
eg: 301 - Moved Permanently
d) 4xx - Client Error
eg: 401 - Unauthorized, 403 - Forbidden, 404 - Not Found,
e) 5xx - Server Error
eg: 500 - Internal Server Error, 502 - Bad Gateway, 503 - Service Unavailable
2. Difference between page directive include, jsp include action and c:import?
<%@ include file="Header.html"/>
<jsp:include page="Header.jsp"/>
<c:import url="http://www.cdnetworksuresh.com/files/file1.html" />
c:import can include external web container urls also, along with static/dynamic file/pages in the same web application.
//TODO:
3. Why do we need to use c:out tag to print a variable instead of printing the EL directly in jsp?
To avoid Cross site Scripting vulnerability.
4. Lets say we have two servlets - FirstServlet.java and SecondServlet.java.
Now my requirement is that once request comes to FirstServlet(url pattern: /first), I have to forward that request to SecondServlet(url pattern: /second) using RequestDispatcher.
Obviously in web.xml, we need to have an entry for FirstServlet.
Do we need to have entry for SecondServlet as well?
Ans: Yes. Since when trying to forward the request to another Servlet using RequestDispatcher, there should be some way to get the Servlet Corresponding to mentioned url pattern. This can be done only through web.xml. So it is mandatory to have <servlet> entry for SecondServlet as well in web.xml
5. Where the compiled jsp class is present in eclipse workspace?
eg: D:\eclipsews\myws\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\ServletProj\org\apache\jsp\jspPage_jsp.java
6. What is the web.xml entry to access a jsp defined under WEB-INF/ folder?
Ans: The files present under /WEB-INF/ folder are secured/protected. User cannot access them directly.
To access a jsp file placed directly under WEB-INF/ folder can be accessed as follows: (mention the jsp file location completely, starting with /WEB-INF)
<servlet>
<servlet-name>One Jsp</servlet-name>
<jsp-file>/WEB-INF/one.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>One Jsp</servlet-name>
<url-pattern>/one</url-pattern>
</servlet-mapping>
7. What are corresponding HTTP methods of Restful web services(CRUD) operations?
Create: POST
Retrieve/Read: GET
Update: PUT
Delete: DELETE
There are 5 types of status codes
a) 1xx - Information
eg: 100 - Continue, 101 - Switching protocols
b) 2xx - Success
eg: 200 - OK
c) 3xx - Redirection
eg: 301 - Moved Permanently
d) 4xx - Client Error
eg: 401 - Unauthorized, 403 - Forbidden, 404 - Not Found,
e) 5xx - Server Error
eg: 500 - Internal Server Error, 502 - Bad Gateway, 503 - Service Unavailable
2. Difference between page directive include, jsp include action and c:import?
<%@ include file="Header.html"/>
<jsp:include page="Header.jsp"/>
<c:import url="http://www.cdnetworksuresh.com/files/file1.html" />
c:import can include external web container urls also, along with static/dynamic file/pages in the same web application.
//TODO:
3. Why do we need to use c:out tag to print a variable instead of printing the EL directly in jsp?
To avoid Cross site Scripting vulnerability.
4. Lets say we have two servlets - FirstServlet.java and SecondServlet.java.
Now my requirement is that once request comes to FirstServlet(url pattern: /first), I have to forward that request to SecondServlet(url pattern: /second) using RequestDispatcher.
Obviously in web.xml, we need to have an entry for FirstServlet.
Do we need to have entry for SecondServlet as well?
Ans: Yes. Since when trying to forward the request to another Servlet using RequestDispatcher, there should be some way to get the Servlet Corresponding to mentioned url pattern. This can be done only through web.xml. So it is mandatory to have <servlet> entry for SecondServlet as well in web.xml
5. Where the compiled jsp class is present in eclipse workspace?
eg: D:\eclipsews\myws\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\ServletProj\org\apache\jsp\jspPage_jsp.java
6. What is the web.xml entry to access a jsp defined under WEB-INF/ folder?
Ans: The files present under /WEB-INF/ folder are secured/protected. User cannot access them directly.
To access a jsp file placed directly under WEB-INF/ folder can be accessed as follows: (mention the jsp file location completely, starting with /WEB-INF)
<servlet>
<servlet-name>One Jsp</servlet-name>
<jsp-file>/WEB-INF/one.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>One Jsp</servlet-name>
<url-pattern>/one</url-pattern>
</servlet-mapping>
7. What are corresponding HTTP methods of Restful web services(CRUD) operations?
Create: POST
Retrieve/Read: GET
Update: PUT
Delete: DELETE