So as I'm trying to run this code example https://www.youtube.com/watch?v=uNRSNDm08wk I did my servlet class and also the form is poiting at it. However when I clic submit it doesn't seem to recognize regServlet as the identifier for my servlet since it's giving me the error 404. It looks for a file inside the jsp page directory. Is there anywhere I can check for those references?
package bean;
import java.io.IOException;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class RegServlet
*/
@WebServlet("/RegServlet")
public class RegServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
StringBuilder csvSkills = new StringBuilder();
/**
* @see HttpServlet#HttpServlet()
*/
public RegServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String hdnParam = request.getParameter("pagename");
if(hdnParam.equals("register")){
....
The html form:
<form action="RegServlet" method="post">
<input type="hidden" name="pagename" value="login"/>
<p>Nombre de Usuario</p>
<input type="text" name="regUserName" required value="usuario" onBlur="if(this.value=='')this.value='usuario'" onFocus="if(this.value=='usuario')this.value='' "><br>
<p>Contraseña</p>
<input type="password" name="regUserPass" required value="Contraseña" onBlur="if(this.value=='')this.value='Contraseña'" onFocus="if(this.value=='Contraseña')this.value='' ">
<br><input type="submit" value="Crear Cuenta">
</form>
I suggest you to add the context inside the action path dynamically in your JSP as:
<form action="${pageContext.request.contextPath}/sampleServlet">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With