Solved

Forwarding to a new jsp without passing quesry string parameters

Posted on 2003-12-11
12
375 Views
Last Modified: 2010-04-01
All :
Is there any to forward to a new JSP ( lets says Test2.jsp ) without passing Query string parameters from another JSP ( lets says Test1.jsp ).
But the limitation is
1) i should not use response.sendReidrect() method
2) The redirect should not pass the Query string parameters from original request to new JSP

I am trying to use RequestDispatcher.redirect(request,response) , but it is passing the Query string parameters to new JSP.

Thanks in advance for your help.

Srinivas
0
Comment
Question by:divvela
  • 3
  • 3
  • 2
  • +2
12 Comments
 
LVL 2

Accepted Solution

by:
anthony_castillon earned 84 total points
ID: 9923626
Use this:

<jsp:forward  .......>
       <jsp:param name="param1"  value="value1"/>
       <jsp:param name="param2"  value="value2"/>

</jsp:forward>
0
 
LVL 2

Expert Comment

by:anthony_castillon
ID: 9923633
0
 

Author Comment

by:divvela
ID: 9924479
Anthony,
<jsp:forward  .......> is also passing Query string parameters from original request to New JSP. I don't want to pass the query string parameters to new JSP.
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 15

Expert Comment

by:jimmack
ID: 9924737
I can't see any documented way around this (though I don't have as much experience with Servlets/JSP as some of the other experts here).

divvela, could you elaborate a bit about why you need to strip the parameters?  Some insight might allow one of us to see a different way of approaching the problem.
0
 

Author Comment

by:divvela
ID: 9925082
jimmack,
I have two JSP's Test1.jsp and Test2.jsp. We will get a request to Test1.jsp with some query string parameters
like this http://server/test1.jsp?par1=1&par2=2....etc
Whenever one of the QueryString parameter(par1,par2 etc....) values are not in the form we expect our JSP will throw ILLEGALARGUMENTEXPECTION . Now what want todo is,
whenever we get the ILLEGALARGUMENTEXPECTION expection because of those query string values we want to redirect it to a Test2.jsp without Querystring values.
I can do it using response.sendRedirect(). But our code somehow does not allow todo this.
So i need a way to redirect it to Test2.jsp from Test1.jsp by stripping off QUery string parameters . Hope i have explained it in a better way. Let me know if you have further more questions .. Thanks you very much for your response.

Srinivas
0
 
LVL 2

Expert Comment

by:anthony_castillon
ID: 9925190
The query string will appear as this

http://server/test1.jsp?par1=1&par2=2....etc

if your <form method="get">.  Use "post" instead.
0
 

Author Comment

by:divvela
ID: 9925218
anthony,
 The request from a software on the client machine. Its not a website . So i cannot change it to Post method.

Srinivas
0
 
LVL 14

Assisted Solution

by:kennethxu
kennethxu earned 83 total points
ID: 9925448
I would suggest you to consider what other experts have suggested, especially I can think of any reason why response.sendRedirect cannot be used.
BUT, if you must to this, there is actually a way to do it.
you'll need to define a java class which implements HttpServletRequest interface:

import java.util.*;
import java.servlet.*;
import java.servlet.http.*;

public class MyHttpRequest implements HttpServletRequest {
  HttpServletRequest raw;
  MyHttpRequest( HttpServletRequest rawRequest ) {
    this.raw = rawRequest;
  }
  public String getParameter( String name ) {
    return null;
  }
  public Enumeration getParameterNames( ) {
    return Collections.enumeration( Collections.EMPTY_LIST );
  }
  public Map getParameterMap() {
    return Collections.EMPTY_MAP;
  }
  public Type allOtherMethodsInInterface( parameter list ) {
    [return] raw.allOtherMethodsInInterface( parameter list );
  }
  ......
}

then you can do:
RequestDispatcher.redirect( new MyHttpRequst(request), response)

let me know if you have futher enquires.
0
 
LVL 6

Assisted Solution

by:jarasa
jarasa earned 83 total points
ID: 10001477
If you just want to call another JSP without any params just do it with JavaScript:

.......
<SCRIPT>
function forward(){
top.location.href="test2.jsp"
}
</SCRIPT>
......
<input type=button OnClick="javascript:forward();">
.....
or directly:
.....
<input type=button OnClick="javascript:top.location.href='test2.jsp';">
.....
Javier
0
 
LVL 6

Expert Comment

by:jarasa
ID: 10001488
If you don't want the Client to interact with your JSP you can also do this
Test1.jsp
..........
Your JSP CODE
.......
<HTML>
<HEAD>
</HEAD>
<BODY>

<P> Please Wait..... </P>

<SCRIPT>
top.location.href="test2.jsp"
</SCRIPT>
</BODY>
</HTML>

This will call Test2.jsp without any parameters and and without client inteeact.

But as Kennethxu says I don't know why you don't want to make a response.sendRedirect....

Javier
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
netstat -a in AIX unix 8 42
java beans and EJBs 5 192
dynamic reloading of jsp in jetty 2 119
maven project jars 7 53
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This article outlines why you need to choose a backup solution that protects your entire environment – including your VMware ESXi and Microsoft Hyper-V virtualization hosts – not just your virtual machines.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question