Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

help in MVC

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

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

Share: 

 

1 Answer Found

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

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);
}}}

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




Tagged: