Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

help in MVC

  Asked By: Ernesta    Date: Sep 08    Category: Java    Views: 484

i need to retrive data from the JSP page and perform validation and
accordingly display the error msg to the user and also the previously
entered values shud be retained



1 Answer Found

Answer #1    Answered By: Reamonn Fischer     Answered On: Sep 08

For Example:

<form name="input" action="/servlet/validation" method="Post">
<table border=0>
<td>Input your name</td>
<td><input type="text" name="name"></td>
<td><input type="submit" value="Submit"></td>

/* 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){
if (name.equals(""){
RequestDispatcher.getRequestDispatcher("error.jsp").forward(request,response); }
PrintWriter out=response.getWriter();
out.print("Hello " +name);

Didn't find what you were looking for? Find more on help in MVC Or get search suggestion and latest updates.