如何阻止GET方法调用的JSP

时间:2014-05-22 17:28:25

标签: jsp methods get block invocation

我有一个像这样编码的现有JSP。

<% 
  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();
}

使用上面提到的JSP,我遇到一个问题,当我使用sample.jsp?userid=dhfgd&token=dhdhd调用JSP时,控件直接转到another.jsp,因为设置了请求参数。

为了避免这种情况,请在不对代码进行太多更改的情况下向我推荐一个可能的解决方案。

1 个答案:

答案 0 :(得分:0)

如果您想要将another.jsp生成的内容包含在实际的响应中,请使用 include 而不是重定向another.jsp sample.jsp页面。

详细了解difference between jsp forward and redirect


您可以使用HttpServletRequest#getMethod()检索请求方法,然后只在JSP中不支持GET请求时发送错误页面。