Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 632
  • Last Modified:

what is equavalent of location.href in jsp?

hi experts,
     below is my code .


public class Str
{
     public static String Replace(String sSource, String sFrom, String sTo)
     {
          int index =0;
          System.out.println("1");
          String dest = "";
          System.out.println("2");
          index = sSource.indexOf(sFrom);
         
          System.out.println("3");
          while (index >= 0)
          {
               
               System.out.println("4");
               dest = sSource.substring(0, index);
               System.out.println("5");
               dest += sTo + sSource.substring(index + sFrom.length());
               System.out.println("6");
               sSource = dest;
               System.out.println("7");
               index = sSource.indexOf(sFrom, index + sTo.length());
               System.out.println("8");
          }
          if (dest == "")
          {
              System.out.println("9");
               dest = sSource;
               System.out.println("10");
          }
          return dest;
     }
}


<%
   Str s =new Str();
%>

<a href="#" onclick="javascript:location.href='<%=s.Replace(request.getRequestURL,"-1","-11");%>'">clickhere</a>






output of request.getRequestURL is below

http://abc.com/webapp/wcs/stores/Store1/StoreCatalogDisplay.jsp

out put of  javascript alert location.href

http://abc.com/webapp/wcs/stores/servlet/StoreCatalogDisplay?param1=100¶m2=401¶m3=-1

i tried request.getRequestURL and request.getQueryString ... but no success?

i want to replace param3=-1 to param3=-11


0
saleemkhan
Asked:
saleemkhan
  • 3
1 Solution
 
damonfCommented:
call request.getParameterNames()  ... this will give you and Enumeration of all the request params.  Loop through each and append to the jsp name ... when you hit param3 change its value before writing it out.
0
 
damonfCommented:
request.getQueryString() only works when you actually included params in the URL ... it won't get params submitted by a form.
0
 
damonfCommented:
So basically you'd have

Enumeration e = request.getParameterNames();
String paramString = "?";
String amp = "";
String currName = "";
while(e.hasMoreElements()){
   currName = (String)e.nextElement();
   paramString += amp + currName + "=" + java.net.URLEncoder.encode(request.getParameter(currName),"UTF-8")
   amp = "&";
}


......................

<a href="#" onclick="javascript:location.href='<%=request.getRequestURI() + paramString%>'">clickhere</a>


You can use your replace function anywhere you want to change the -1 to -11.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now