0

Trying to learn JSP and making my first project, and I absolutely cannot get the url mapping to work. I tried mapping in web.xml at first, but that didn't work, so I upgraded to javax servlet 3.0.1 and tried the annotation mapping, but again I get a 404 error. Not sure what I'm doing wrong.

I have a simple html form with

<form action="Login" method="POST">
        <div align="center">
            <table>
                <tr>
                    <td>User Name</td>
                    <td><input type="text" name="username" /></td>
                </tr>
                <tr>
                    <td>Password</td>
                    <td><input type="password" name="password" /></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="submit" value="Login" /></td>
                </tr>
            </table>
        </div>
    </form>

and a Servlet with

@WebServlet("/Login")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    //...
}

Can anyone please advise me on what I may be doing wrong? Thanks

SW Williams
  • 559
  • 1
  • 5
  • 18
  • Are you deploying to a webapp? That is, maybe you need to go to something like http://localhost:8080/someappname/login.jsp to get to the JSP. If that is the case you'll need to include the webapp name for the servlet too. – stdunbar Jan 23 '17 at 03:18
  • Fix your form action to something like this: `
    `.
    – W-S Jan 23 '17 at 03:57
  • Check the following post: http://stackoverflow.com/questions/11731377/servlet-returns-http-status-404-the-requested-resource-servlet-is-not-availa – W-S Jan 23 '17 at 03:59
  • Yes its a webapp, I'm using intellij to deploy the tomcat server. My app is at the root, http://localhost:8080/index.jsp. Shouldn't http://localhost:8080/Login work? – SW Williams Jan 23 '17 at 04:00
  • Even if i move my app context out of the root and into a directory like localhost:8080/Project/Login I still get 404 – SW Williams Jan 23 '17 at 04:32
  • Which version of Apache Tomcat are you using? – W-S Jan 23 '17 at 06:31
  • 8.5. I think this an issuewith IntelliJ and Tomcat because I got the same code and configuration and when I deploy Tomcat with eclipse it works – SW Williams Jan 23 '17 at 09:49

0 Answers0