简体   繁体   中英

How to redirect URLs to login page?

I have an application which has a login page which comes up with the URL:

http://localhost:8080/Analyze

when the user fills the login page and clicks submit.it goes to a page with the URL:

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

HTTP Status 405 - HTTP method GET is not supported by this URL

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.

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. If you're in a servlet you'd do something like this:

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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