JaiswalTraining

Get the online training



Corejava Servlet Jsp  Php  Hibernate  Ajax Web Service   Ejb2.1 Ejb3.0 Struts Struts2  JPA Spring Ibatis   JSF    JSF2.0  CoreJavaDesignPattern    Jquery  Flex J2EE-Design-Patterns  Jboss7  Maven  Contact Me                                                                                                                                                                        
            IGNOU SMU PTU Project                                           Training                                                                                                                              
              

Contact Us  0091- 9210721663         jaiswaltraining@gmail.com




Corejava
Servlet
Jsp
Php
Hibernate
Ajax
Web Service
Ejb2.1
Ejb3.0
Struts  
Struts2
JPA
Spring
Ibatis
JSF
JSF2.0
CoreJavaDesignPattern
Jquery
Flex
J2EE-Design-Patterns
Jboss7
Maven







JSP Action

<jsp:forward/>

  • This is used to send the request object from one page  to another page..
  • this alternate of RequestDispatcher of servlet with forword method. 
  • it carries attributes as well as parameters.
  • it forwards only dynamic contents.
  • iit sends the parameter via 
    • <jsp:param value="" name=""/>
<jsp:inlcude/>
  • This is used to inlcude the request object from one page  to another page..
  • this alternate of RequestDispatcher of servlet with inlcude method. 
  • it carries attributes as well as parameters.
  • it inlcudes only dynamic contents.

Example

login.jsp
<html>

<body>

<form action="login2.jsp">
<table>

  <tr>
    <td>name</td>
    <td><input type="text" name="n"></td>
  </tr>

  <tr>
    <td>age</td>
    <td><input type="text" name="a"></td>
  </tr>

  <tr>
    <td>Gender</td>
    <td></td>
  </tr>

  <tr>
    <td>Male</td>
    <td><input type="radio" name="gen" value="male" checked="checked"></td>
  </tr>

  <tr>
    <td>Female</td>
    <td><input type="radio" name="gen" value="female"></td>
  </tr>
  <tr>
    <td></td>
    <td><input type="submit"></td>
  </tr>
</table>
</form>

</body>
</html>
Download code

login2.jsp


<%
  String gen = request.getParameter("gen");
  out.print("<h1>this is login page</h1>");

  if (gen.equals("male")) {
    request.setAttribute("sal"10000);
  %>

<jsp:forward page="male.jsp" >
<jsp:param value="HCL" name="cname"/>
</jsp:forward>
<%
  else if (gen.equals("female")) {
    request.setAttribute("sal"12000);
    
%>
<jsp:forward page="female.jsp" >
<jsp:param value="IBM" name="cname2"/>
</jsp:forward>
<%
  }
%>
Download code

male.jsp

<%
  out.print("<h1>male section</h1>");
  out.print("Hello Mr. " + request.getParameter("n"));
  out.print("<br>age is " + request.getParameter("a"));
  out.print("<br>salary  is " + request.getAttribute("sal"));
  out.print("<br>company name is   " + request.getParameter("cname"));

%>
Download code

female.jsp

<%
  out.print("<h1>female section</h1>");
  out.print("Hello Mrs. " + request.getParameter("n"));
  out.print("<br>age is " + request.getParameter("a"));
  out.print("<br>salary  is " + request.getAttribute("sal"));
  out.print("<br>company name is   " + request.getParameter("cname"));


%>
Download code
Download Zip code
Output


This example take the user inputs.
as per the thier gender forword the page to respective jsp.




  • when user click on submit button, request instead of going to male.jsp goes to login2.jsp.
  • login2.jsp deceides where to forword request male.jsp or female.jsp as per criteria.
  • the real page url is not shown on the browser.
  • as you can see the male.jsp url ican't been seen.
i