Unable to call servlet file from jsp - 404 error found [duplicate]

Unable to call servlet file from jsp - 404 error found [duplicate]



This question already has an answer here:



My index page i have changed to Register_1.jsp and updated in xml file too and the page is running fine with action field to connect servlet file Guru_register i have added jsp code along with java code and structure in eclipse in image below please help me Thanks in advance...!!



Structure in eclipse



Register_1.jsp


<body>
<h1>Guru Register Form</h1>
<form action="Guru_register.java" method="post">
<table style="with: 50%">
<tr>
<td>First Name</td>
<td><input type="text" name="first_name" /></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="last_name" /></td>
</tr>
<tr>
<td>UserName</td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" name="address" /></td>
</tr>
<tr>
<td>Contact No</td>
<td><input type="text" name="contact" /></td>
</tr></table>
<input type="submit" value="Submit" /></form>
</body>



Register_2.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>Guru Success Page</title>
</head>
<body>
<a><b>Welcome User!!!!</b></a>
</body>
</html>



My servlet class


public class Guru_register extends HttpServlet
private static final long serialVersionUID = 1L;


protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException last_name.isEmpty()




What i have tried in two ways submitted form with values and without either way getting same error.



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




2 Answers
2



You need to give Servlet Name in the action do not need to specify anything;


<body>
<h1>Guru Register Form</h1>
<form action="Guru_register" method="post">



//Servlet with annotation


@WebServlet("/Guru_register")
public class Guru_register extends HttpServlet {
private static final long serialVersionUID = 1L;





Hi Prabath i did added annotations like you said before the class begins then also same result i am going to remove cache and try re run again. Thanks for your time Prabath @WebServlet("/Guru_register") public class Guru_register extends HttpServlet { private static final long serialVersionUID = 1L;
– Atom
Aug 25 at 1:44





bro still the same error after adding annotation
– Atom
Aug 25 at 2:02





it is working fine now bro i changed in action field to Guru_register as you mentioned it is working fine now
– Atom
Aug 25 at 2:11





Why with .java extension in action field is not working bro...?
– Atom
Aug 25 at 2:13





HTML engine do not recognize java, that's why we need JSP. With Mapping we give a Servlet a name, a URL and force HTML to identify a Servlet by this particular URL. If you ask HTML tag to identify abc.java it looks in Mapping and it wont identify it.
– Prabath
Aug 25 at 2:56



Try adding servlet info to web.xml
First move your servlet to a package, lets call it 'controllers', so the file's new location would be src > controllers > Guru_register.java


<servlet>
<servlet-name>Guru_register</servlet-name>
<servlet-path>controllers.Guru_register</servlet-path>
</servlet>
<servlet-mapping>
<servlet-name>Guru_register</servlet-name>
<url-pattern>/guru-register</url-pattern>
</servlet-mapping>



Next, modify jsp form as follows:


<form action="guru-register" method="post">





Hi Arvind bro, yeah this is another way right i mean without using annotation this one also would work i assume. thanks for letting me to learn new one
– Atom
Aug 25 at 2:17

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế