For Example:
//input.jsp
<form name="input" action="/servlet/validation" method="Post">
<table border=0>
<tr>
<td>Input your name</td>
<td><input type="text" name="name"></td>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
//web-inf/classes/
/* file name = "validation.java" */
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
public class validation extends HttpServlet{
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
String name = request.getParameter("name");
if (name==null){
name="";
}
if (name.equals(""){
RequestDispatcher.getRequestDispatcher("error.jsp").forward(request,response); }
else{
PrintWriter out=response.getWriter();
out.print("Hello " +name);
}}}