• Post Reply Bookmark Topic Watch Topic
  • New Topic

HTTP Status 404 Error it cannot find the Servlet Intellij Idea

 
kwosh vick
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi a new to JSPs and Servlet. Am try to Display the Users entered username and password
The Index.jsp has lthe login form and the Servlet(Servletme) is supposed to display what the entered username and password are , but it only dispalys the login form after filling in the username and password it faills to find the Servlet. Am using Intellij idea

The index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>


<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSP Servlet Example</title>
</head>
<body>

<div align="center" style="margin-top: 50px;">

<form action="Servletme">
Please enter your Username: <input type="text" name="username" size="20px"> <br>
Please enter your Password: <input type="text" name="password" size="20px"> <br><br>
<input type="submit" value="submit">
</form>

</div>

</body>
</html>

The Servlet me
package me;

import java.io.IOException;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

/**
* Created with IntelliJ IDEA.

* Date: 13/06/14
* Time: 10:07
* To change this template use File | Settings | File Templates.
*/
public class Servletme extends javax.servlet.http.HttpServlet {
protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {

}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// reading the user input
String username = request.getParameter("username");
String password = request.getParameter("password");
PrintWriter out = response.getWriter();
out.println (
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" +" +
"http://www.w3.org/TR/html4/loose.dtd\">\n" +
"<html> \n" +
"<head> \n" +
"<meta http-equiv=\"Content-Type\" content=\"text/html; " +
"charset=ISO-8859-1\"> \n" +
"<title> Crunchify.com JSP Servlet Example </title> \n" +
"</head> \n" +
"<body> <div align='center'> \n" +
"<style= \"font-size=\"12px\" color='black'\"" + "\">" +
"Username: " + username + " <br> " +
"Password: " + password +
"</font></body> \n" +
"</html>"
);
}
}

the web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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_2_5.xsd"
version="2.5">

<servlet>
<servlet-name>Servletme</servlet-name>
<servlet-class>Servletme</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servletme</servlet-name>
<url-pattern>/Servletme</url-pattern>
</servlet-mapping>

</web-app>
intellij.png
[Thumbnail for intellij.png]
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your servlet is in a package but you have not specified the full name including the package in your web.xml See also the ServletsFAQ
 
kwosh vick
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have added the package in the web.xml

but still no effect
1.png
[Thumbnail for 1.png]
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is not how you add a package name in the web.xml. You are supposed to add it on the servlet class declaration like



Are you using a book/tutorial to learn how to develop servlets and configure them? If not then you should get a book or tutorial. It's better/faster than trying to guess what you are supposed to do.
 
kwosh vick
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope am neither using a book nor a tutorial just the internet
what about the servlet mapping?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!