include action vs forward action JSP
Before going into this tabulation of include action vs forward action JSP, is is advised to read clearly about jsp:include action and jsp:forwrd action. The examples are given in simple terms and screenshots of explanation.
Difference comes in the way they are treated by container. They are worked differently.
It is the same differences between include and forward in RequestDispatcher given earlier.
Property | include action – jsp:include | forward action – jsp:forward |
---|---|---|
Occurs | At translation time | At request time |
Performance | Comparatively slower | Faster |
No. Servlets created | Only one | Multiple |
Response Data sent | Includes both including and included JSPs | Goes only that of included JSP |
Used when | When content of included file DOES NOT CHANGE often like advertisement banners | When content of included file CHANGES often like share price |
Transfer of control | Execution control shifts temporarily from including file to included file. When included file is executed, the control transfers back to including file. | Shifts permanently from including file to included file. After the execution of included file, the control goes to client directly but not returned to including file. |
Response to client | Goes from the same JSP which client requested. | Goes from a different JSP |
Merge of response | Both responses of including and included files merged and sent client | No merging happens. Only included response goes to client |
Extra activity | When control returned to including file, extra activity like including another JSP file can be done. | As control never returns, no extra activity can be done in including file. |
Extra activity | When control returned to including file, extra activity like including another JSP file can be done. | As control never returns, no extra activity can be done in including file. |
Similarities:
1. Usage depends on the application. But mostly used include action.
2. Both takes optional flush attribute.
3. Both takes additional parameters. This is explained in JSP include action with Parameter passing Example and JSP forward action with Parameters Example.
loda lasan