I'm creating a login page and want to hide .jsp
into URL bar, So i tried to use the following:
Here my loginPage.jsp
:
<form class="m-t-md" action="loginAccount">
<div class="form-group">
<input type="email" name="email" class="form-control" placeholder="Email" required>
</div>
<div class="form-group">
<input type="password" password="password" class="form-control" placeholder="Password" required>
</div>
<button type="submit" class="btn btn-success btn-block">Login</button>
<a href="forgot.html" class="display-block text-center m-t-md text-sm">Forgot Password?</a>
<p class="text-center m-t-xs text-sm">Do not have an account?</p>
<a href="signup" class="btn btn-default btn-block m-t-md">Create an account</a>
</form>
here is my login
where i'm calling loginPage.jsp
using RequestDispatcher
:
public class login extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{
response.setContentType("text/html");
RequestDispatcher RequetsDispatcherObj =request.getRequestDispatcher("./loginPage.jsp");
RequetsDispatcherObj.forward(request, response);
}
}
Which gives me this error:
I did used as well doPost
instead doGet
but still getting the same error.
HELP WOULD BE APPRECIATED!!
EDITED
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
metadata-complete="false">
<servlet>
<servlet-name>index</servlet-name>
<servlet-class>com.pages.index</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>index</servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>com.pages.login</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>loginAccount</servlet-name>
<servlet-class>com.login.loginAccount</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>loginAccount</servlet-name>
<url-pattern>/loginAccount</url-pattern>
</servlet-mapping>
</web-app>
I see that you have 2 servlets here pertaining to login. One is com.pages.login
and another com.login.loginAccount
. However, your form submission will be passed on to your com.login.loginAccount
(and not to your com.pages.login
servlet). This is clearly indicated in the action attribute of your form:
<form class="m-t-md" action="loginAccount">
You posted code from your com.pages.login
servlet. However, it is not the one handling the form submission. You can do one of the following:
Edit your servlet com.login.loginAccount
. Make sure that doGet
method is declare to handle the form submssion.
package com.login;
public class loginAccount extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
...
}
...
}
Or you can update your form element, add method attribute and set it to POST
<form class="m-t-md" action="loginAccount" method="POST">
Your form says action=loginAccount
, /loginAccount
url is mapped to servlet name loginAccount
. Servlet loginAccount
points to class com.login.loginAccount
. You may point the /loginAccount
mapping to servlet with name login
:
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/loginAccount</url-pattern>
</servlet-mapping>
OR
Change your form action to login
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.