0

I have an existing JSP which is coded like this.

<% 
  if( (request.getParameter("userid")!=null) && (request.getParameter("token")!=null) ) {

     session.setParameter("USERID", request.getParameter(userid);
     session.setParameter("Token", request.getParameter(token);

     send.redirect(another.jsp);
  }
%>

< ----- here i have the normal HTML contents where i ask for userid from the user 
        and upon clicking submit, java script function openwindow() is called ----- >

function openwindow(){

   < -- here i open a modal window which calls a URL with userid (get method) 
        and as return value i get userid and token back. 
        Now i set this to document.Parent.userid and document.Parent.token --- >

    document.Parent.userid = retval.userid;
    document.Parent.token = retval.token;
    Parent.submit();
}

With the above mentioned JSP, I face a problem that when I invoke the JSP using sample.jsp?userid=dhfgd&token=dhdhd, the control directly goes to another.jsp since the request parameters are set.

To avoid this, kindly suggest me a probable solution without making much changes in code.

ebo
  • 2,717
  • 1
  • 27
  • 22
  • You are redirecting to `another.jsp` if `userid` and `token` is not `null` then where is the issue? – Braj May 22 '14 at 18:13

1 Answers1

0

Use include instead of redirect to another.jsp if you want to include the content generated by another.jsp as well in the response of the actual sample.jsp page.

Read more about the difference between jsp forward and redirect


You can retrieve the request method using HttpServletRequest#getMethod() and then simply send an error page if GET request is not supported in JSP.

Community
  • 1
  • 1
Braj
  • 46,415
  • 5
  • 60
  • 76