1 Replies - 1404 Views - Last Post: 02 September 2012 - 06:44 PM

#1 princess18  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 79
  • Joined: 07-December 09

Form submitted in servlet

Posted 02 September 2012 - 06:23 PM

My inputted data is note display in the same page when I click on the submit button. Please help me. Whenever submit button is clicked, the inputted values in the textboxes, checkboxes, etc should be displayed in the same page. Here's my code:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HW extends HttpServlet{

	public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
		{
			response.setContentType("text/html");
			PrintWriter pw = response.getWriter();
			pw.println("<html>");
			pw.println("<head><title>Home Page</title></title>");
			pw.println("<body>");
			pw.println("<FORM method= post>");
pw.println("<TABLE BORDER= 1>");
    pw.println("<TR>");
        pw.println("<TD>Personal Information</TD>");
    pw.println("</TR>");
   
    pw.println("<TR>");
        pw.println("<TD>");
            pw.println("<TABLE>");
           
            pw.println("<TR>");
                pw.println("<TD>First Name:</TD>");
                pw.println("<TD><input type= text name= fname/></TD>");
            pw.println("</TR>");
           
            pw.println("<TR>");
                pw.println("<TD>Last Name:</TD>");
                pw.println("<TD><input type= text name= lname/></TD>");
            pw.println("</TR>");
           
            pw.println("<TR>");
                pw.println("<TD>Middle Name:</TD>");
                pw.println("<TD><input type= text name= mname/></TD>");
            pw.println("</TR>");

            pw.println("<TR>");
                pw.println("<TD>Address:</TD>");
                pw.println("<TD><input type= text name= address/></TD>");
            pw.println("</TR>");
           
            pw.println("<TR>");
            pw.println("<TD>Country:</TD>");
			pw.println("<TD>");
				pw.println("<select name=Country>");
					pw.println("<option value=1>Philippines</option>");
					pw.println("<option value=2>Japan</option>");
					pw.println("<option value=3>China</option>");
					pw.println("<option value=4>Thailand</option>");
					pw.println("<option value=5>Singapore</option>");
					pw.println("<option value=6>Malaysia</option>");
					pw.println("<option value=7>Others</option>");
				pw.println("</select>");
			pw.println("</TD>");
            pw.println("</TR>");
           
            pw.println("<TR>");
                pw.println("<TD>Gender:</TD>");
                pw.println("<TD><input type= radio name= gender value=male/>Male</TD>");
                pw.println("<TD><input type= radio name= gender value=female/>Female</TD>");
            pw.println("</TR>");
           
            pw.println("</TABLE>");
        pw.println("</TD>");
    pw.println("</TR>");
   
    pw.println("<TR>");
        pw.println("<TD>Account Information</TD>");
    pw.println("</TR>");
   
    pw.println("<TR>");
        pw.println("<TD>");
            pw.println("<TABLE>");
           
            pw.println("<TR>");
                pw.println("<TD>Username:</TD>");
                pw.println("<TD><input type= text name= uname/></TD>");
            pw.println("</TR>");
           
            pw.println("<TR>");
                pw.println("<TD>Password:</TD>");
                pw.println("<TD><input type= password name= password/></TD>");
            pw.println("</TR>");
           
            pw.println("<TR>");
                pw.println("<TD>Confirm Password:</TD>");
                pw.println("<TD><input type= password name= password/></TD>");
            pw.println("</TR>");
           
            pw.println("<TR>");
                pw.println("<TD>E-mail Address:</TD>");
                pw.println("<TD><input type= text name= eadd/><br/></TD>");
            pw.println("</TR>");
           
            pw.println("</TABLE>");
        pw.println("</TD>");
    pw.println("</TR>");
   
pw.println("</TABLE>");

pw.println("<input type= checkbox name= chkbox/>I have agreed to the terms and conditions<br/>");
pw.println("<input name= submit type= submit value= Submit>");
pw.println("<input name= submit type= reset value= Reset>");
pw.println("</FORM>");

pw.println("if (request.getParameter(submit) != null)");
pw.println("{");
    pw.println("request.getParameter(fname)");
pw.println("}"); 
//else {
    // Form is not submitted.
//}


//Welcome <?php echo $_POST["fname"]; ?>!<br />
//You are <?php echo $_POST["age"]; ?> years old. 

pw.println("Name: ");
pw.println("<?php echo $_POST[fname]; ?>");

pw.println("</body></html>");

		}
		
		//public void doPost(HttpServletRequest request,
                    // HttpServletResponse response)
      //throws ServletException, IOException {
     //doGet(request, response);
  }




Thank you!

Please disregard the PHP codes.

Is This A Good Question/Topic? 0
  • +

Replies To: Form submitted in servlet

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10180
  • View blog
  • Posts: 37,585
  • Joined: 27-December 08

Re: Form submitted in servlet

Posted 02 September 2012 - 06:44 PM

Moved to Java EE. Please post in the appropriate forum in the future.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1