Java write a simple form program

Source: Internet
Author: User

This is under the Java program

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

public class Formdemo extends httpservlet{
public void doget (HttpServletRequest request,httpservletresponse response) {
try{
Response.setcontenttype ("text/html;charset=gb2312"); Set Head
PrintWriter Out=response.getwriter (); Get PrintWriter Instance
String Name,age,sex,phone,address,email; Variable declaration
Name=request.getparameter ("Name"); Get the parameters
Sex=request.getparameter ("Sex");
Phone=request.getparameter ("Phone");
Address=request.getparameter ("Address");
Email=request.getparameter ("Email");
Out.println ("<HTML><HEAD><TITLE>a</TITLE></HEAD>"); Output information to the client
Out.println ("<BODY>");
Out.println ("<P><H3> Name:" +converttochinese (name) + "</H3></P>");
Out.println ("<P><H3> Sex:" +converttochinese (Sex) + "</H3></P>");
Out.println ("<P><H3> Tel:" +phone+ "</H3></P>");
Out.println ("<P><H3> address:" +converttochinese) + "</H3></P>");
Out.println ("<P><H3> e-mail:" +email+ "</H3></P>");
Out.println ("</BODY></HTML>");

}
catch (Exception ex) {
Ex.printstacktrace (); Output error message
}
}

private string Converttochinese (string source) {
String s= "";
try{
S=new String (source.getbytes ("iso8859_1")); Character encoding Conversion
}
catch (Java.io.UnsupportedEncodingException ex) {
Ex.printstacktrace (); Output error message
}
return s; Returns the converted String
}
}

The next page is the HTML program.

<HTML>
<HEAD>
<TITLE> Simple Form Program </TITLE>
</HEAD>
<BODY>
<CENTER>
<form action= "Http://localhost:8080/servlet/FormDemo" >
<table border= "0" cellpadding= "3" >
<TR>
<TD> name:</td>
<td><input type= "text" name= "NAME" ></TD>
</TR>
<TR>
<TD> Sex:</td>
<td><input type= "Radio" name= "Sex" value= "male" checked> male
<input type= "Radio" name= "Sex" value= "female" checked> female </TD>
</TR>
<TR>
<TD> Telephone:</td>
<td><input type= "text" name= "Phone" ></TD>
</TR>
<TR>
<TD> Address:</td>
<td><input type= "text" name= "Address" ></TD>
</TR>
<TR>
<TD> e-Mail:</td>
<td><input type= "text" name= "Email" ></TD>
</TR>
<TR>
&LT;TD align= "center" colspan= "2" >
<input type= "Submit" value= "Submit" >
<input type= "reset" value= "reset" >
</TD>
</TR>
</TABLE>
</FORM>

</center>
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.