File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes how to replace requestDispatcher.include() with tags in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "how to replace requestDispatcher.include() with tags in jsp" Watch "how to replace requestDispatcher.include() with tags in jsp" New topic
Author

how to replace requestDispatcher.include() with tags in jsp

Abdul Aatif
Greenhorn

Joined: Feb 08, 2012
Posts: 23
hello all,
I have written a two JSP's(one.jsp and two.jsp), One.jsp has a table with 3 text field's and button. If the user clicks on button, the request is sent to two.jsp, and in two.jsp the i am placing some data into request Scope variables and forwarding( using <%@ include file="index.jsp" %>) the request to one.jsp, But the problem is i am unable to get the values stored in request scope in one.jsp. And if i am using requestDispatcher.include() it is working.

so how to replace requestDispatcher.include() with tags in jsp.

===========================one.jsp========================

<%@ page isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>

</head>
<body bgcolor="lightblue">
<center>
<form action="two.jsp" method="post" name="myForm" >



<table border="1">
<tr><td>deptno</td> <td><input type="text" name="n1" value=${dno} ></td></tr>
<tr><td>deptname</td><td><input type="text" name="n2" value=${dname} ></td></tr>
<tr><td>Loc</td><td><input type="text" name="n3" value=${dloc} ></td></tr>
</table>


<input type="submit" name="submitting" value="first" >
</form>
</center>


</body>
</html>
============================two.jsp===================================


<%@ page isELIgnored="false" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


<%@ include file="one.jsp" %>

<c:set scope="page" var="s" value="${param.submitting}"></c:set>
<c:set scope="page" var="first" value="first"></c:set>



<c:choose>

<c:when test="${pageScope.s == pageScope.first }">

<c:set scope="request" var="dno" value="one" ></c:set>
<c:set scope="request" var="dname" value="one name"></c:set>
<c:set scope="request" var="dloc" value="one sal"></c:set>

</c:when>


<c:when test="${pageScope.s == pageScope.last }">

</c:when>

<c:otherwise>
<c:out value="hmmm" ></c:out>
</c:otherwise>
</c:choose>



========================================================

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

Problems like this can be solved by following best practices. Submitting a form to a JSP is not the correct way to do things. You should be submitting to a servlet controller. Read this article for more information.

Regardless, request-scoped variables will never be available in a different request.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
hari vis
Greenhorn

Joined: Aug 05, 2012
Posts: 3
try <jsp:include> tag.
Abdul Aatif
Greenhorn

Joined: Feb 08, 2012
Posts: 23
Bear Bibeault wrote:Problems like this can be solved by following best practices. Submitting a form to a JSP is not the correct way to do things. You should be submitting to a servlet controller. Read this article for more information.

Regardless, request-scoped variables will never be available in a different request.




Sir, but if i am using

<%
RequestDispatcher rd = request.getRequestDispatcher("one.jsp");
rd.include(requset,forward);
%>

It is working Fine.


Abdul Aatif
Greenhorn

Joined: Feb 08, 2012
Posts: 23
hari vis wrote:try <jsp:include> tag.



Sir i have used <jsp:include> to replace requestDispatcher.include() , i am unable to pass request object to another page using JSP TAG'S



Thanks in advance.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

Please read ItDoesntWorkIsUseless. SHow us what you are doing and exactly what is happening. Making us guess won't get you much help.
hari vis
Greenhorn

Joined: Aug 05, 2012
Posts: 3
Latif Khan wrote:
hari vis wrote:try <jsp:include> tag.



Sir i have used <jsp:include> to replace requestDispatcher.include() , i am unable to pass request object to another page using JSP TAG'S



Thanks in advance.


You don't need to pass request objects between JSPs, unlike Servlets. They are implicitly available, use the implicit 'request' object.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to replace requestDispatcher.include() with tags in jsp