Give one another example:
Establish an engineering GiveYou (don't forget web-infers and her children)
Write three files in GiveYou
1: login.jsp content as follows
<% @ Page ContentType = "text / html; charset = GB2312"%>
td>
TR>
TABLE>
center>
form>
Html>
2: Success.jsp contents are as follows
hEAD>
body>
html>
3: Error.jsp content is as follows
Built newly built your project in Eclipe, also named GiveYou (put your source file (.java) in Mythree --- javasource, put your class file (.class) in Mythree --- Web- Inf --- Classes inside), don't forget to import servlet.jar
Write a class TEST, the content is as follows:
Import java.io. *;
Import javax.servlet. *;
Import javax.servlet.http. *;
Public Class Test Extends Httpservlet
{
Private string Userid, Password;
Public void dopost (httpservletRequest RQ,
HTTPSERVLETRESPONSE RP)
THROWS IOEXCEPTION, ServletException
Rp.setContentType ("text / html; charSet = GB2312");
PrintWriter out = rp.getwriter ();
Userid = RQ.GetParameter ("UserName");
Password = rq.getParameter ("password");
IF ((Userid! = null) && (Password! = null))
rp.sendredirect ("/ GiveYou / Success.jsp");
}
Else
rp.sendredirect ("/ GiveYou / Error.jsp");
Since Web.xml is the same as Mythree, I don't say it here.
Please launch your Tomcat again
Enter: in your IE address bar:
Http: // localhost: 8080 / giveyou /login.jsp
This chapter is written in this chapter: When you come here, you must have been very impatient, think that my "no nonsense" became "nonsense,", ", my brother, my brother, to the above example, do you think you are not You can write it slightly more complicated, slightly beautiful, don't let the page are so pale, don't let the text always have such a sigh, do dozens of classes, call each other, in dopost () Write a conditional statement, jump to different page interviews according to different values obtained, I believe that your program will never be so lonely.