Can I run my dynamic web app in eclipse without web.xml and without @WebServlet("/Myservlet")?
I have three html files and one servlet in an example given in my book but it is not running in eclipse. When i run eclipse it gives an error: 404 source not found
. I also noticed that no servlet is showing in TrainingServlets(myprojectname)/deployment descriptor/servlets area.
Code for them is below
**login.html**
<!DOCTYPE html>
<html>
<meta charset="ISO-8859-1">
<body>
<h2>Please provide login details</h2>
<form method="post" action="http://localhost/TrainingServlets/myservlet" name="myForm">
<br>User Id:
<input type="text" name="userid"/>
<br>Password:
<input type="password" name="pwd">
<br><br>
<input type="submit" value="Submit Form"/>
</form>
</body>
</html>
**welcome.html**
<!DOCTYPE html>
<html>
<meta charset="ISO-8859-1">
<body>
<h2>You have successfully logged in</h2>
</body>
</html>
**register.html**
<!DOCTYPE html>
<html>
<meta charset="ISO-8859-1">
<body>
<h2>Your login is incorrect.Please register yourself</h2>
<form method="post" action="" name="myform">
<br>Name:
<input type="text" name="userid"/>
<br> Address:
<input type="text" name="address"/>
<br> Phone No:
<input type="text" name="phoneno"/>
<br><br>
<input type="submit" value="Register"/>
</form>
</body>
</html>
**MyServlet**
package com;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Myservlet extends HttpServlet{
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
processRequest(request,response);
}
protected void doPOST(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
processRequest(request,response);
}
protected void processRequest(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
String id = request.getParameter("userid");
String pwd = request.getParameter("pwd");
if (id.equals("ali")&& pwd.equals("vu")) {
response.sendRedirect("welcome.html");
}else{
response.sendRedirect("register.html");
response.sendError(response.SC_PROXY_AUTHENTICATION_REQUIRED,"Send Error Demo");
}
}
}
public static void main(String [] args)
for your java based web application. An absolute must! – shinjw