简体   繁体   English

如何将URL重定向到登录页面?

[英]How to redirect URLs to login page?

I have an application which has a login page which comes up with the URL: 我有一个带有登录页面的应用程序,其中包含URL:

http://localhost:8080/Analyze http:// localhost:8080 /分析

when the user fills the login page and clicks submit.it goes to a page with the URL: 当用户填写登录页面并单击Submit时,它将转到具有URL的页面:

http://localhost:8080/Analyze/analyze http:// localhost:8080 / Analyze / analyze

Now if i copy the url:http://localhost:8080/Analyze/analyze and paste in a new browser window I get 现在,如果我复制url:http:// localhost:8080 / Analyze / analyze并粘贴到新的浏览器窗口中,

HTTP Status 405 - HTTP method GET is not supported by this URL HTTP状态405-此URL不支持HTTP方法GET

What can I do to redirect back to the login page: 我该怎么做才能重定向回登录页面:

http://localhost:8080/Analyze if I copy paste http://localhost:8080/Analyze/analyze in a new browser window. 如果我复制http:// localhost:8080 / Analyze,则将http:// localhost:8080 / Analyze / analyze复制并粘贴到新的浏览器窗口中。

You didn't state how you are handling the requests so my answer is necessarily vague. 您没有说明您如何处理请求,因此我的答案肯定含糊。

For that URL you need to write code to handle the HTTP GET method and forward the request to the page you want. 对于该URL,您需要编写代码来处理HTTP GET方法并将请求转发到所需的页面。 If you're in a servlet you'd do something like this: 如果您在servlet中,则可以执行以下操作:

protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException
{
  String urlStr = "/Analyze";
  RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
  dispatcher.forward(req, resp);
}

I'm guessing you're taking POST data from the login page. 我猜您正在从登录页面获取POST数据。

Perhaps a solution would be to check for the existence of login data, without any data being passed, you could redirect to localhost:8080/Analyze 也许一种解决方案是检查登录数据是否存在,而不传递任何数据,您可以重定向到localhost:8080 / Analyze

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM