Who can help me see what the problem is? Thank you!
Register.html:
CopyCode The Code is as follows: <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Title> register.html </title>
<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "Description" content = "this is my page">
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<! -- <LINK rel = "stylesheet" type = "text/CSS" href = "./styles.css"> -->
</Head>
<Body>
<Br>
<Form action = "register. jsp" method = "Post" name = "frm">
Username: <input type = "text" name = "in_username"> <br>
Password: <input type = "password" name = "in_password"> <br>
<Input type = "Submit" name = "Submit" value = "Submit">
</Form>
</Body>
</Html>
Register. jsp part: Copy code The Code is as follows: <% @ page Language = "Java" Import = java. util. * pageencoding = "ISO-8859-1" %>
<%
String Path = request. getcontextpath ();
String basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/";
%>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Base href = "<% = basepath %>">
<Title> my JSP 'register. jsp 'starting page </title>
<Meta http-equiv = "Pragma" content = "no-Cache">
<Meta http-equiv = "cache-control" content = "no-Cache">
<Meta http-equiv = "expires" content = "0">
<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "Description" content = "this is my page">
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<! --
<LINK rel = "stylesheet" type = "text/CSS" href = "styles.css">
-->
</Head>
<Body>
<Br>
<%! Boolean isnotlogin = false; %>
<%
String username = request. getparameter ("username ");
String Password = request. getparameter ("password ");
If (username = NULL | Password = NULL)
{
Response. sendredirect ("error. jsp ");
Return;
}
%>
<JSP: usebean id = "person" Scope = "page" class = "mypack. Register">
<JSP: setproperty name = "person" property = "username" Param = "username"/>
<JSP: setproperty name = "person" property = "PWD" Param = "password"/>
</Jsp: usebean>
<%
Isnotlogin = person. Judge ();
If (! Isnotlogin)
{
Response. sendredirect ("error. jsp ");
Return;
}
Else
{
Session. setattribute ("username", request. getparameter ("username "));
%>
<JSP: Forward page = "sbmt">
<JSP: Param name = "username" value = "<% = username %>"/>
</Jsp: Forward>
<%
}
%>
</Body>
</Html>
Register. Java (JavaBean) Section: Copy code The Code is as follows: Package mypack;
Public class register {
Private string username = "";
Private string Pwd = "";
Public void setusername (string nm)
{
This. Username = Nm;
}
Public String GetUserName ()
{
Return this. Username;
}
Public void setpwd (string PD)
{
This. Pwd = Pd;
}
Public String getpwd ()
{
Return this. pwd;
}
Public Boolean judge ()
{
Boolean temp = false;
If (username. Equals ("teacher") & PWD. Equals ("teacher "))
{
Temp = true;
}
Return temp;
}
}
Sbmt. Java (servlet) Section:
Package mypack;
Import java. Io. ioexception;
Import java. Io. printwriter;
Import javax. servlet. servletexception;
Import javax. servlet. http. httpservlet;
Import javax. servlet. http. httpservletrequest;
Import javax. servlet. http. httpservletresponse;
Import javax. servlet. http. httpsession;
Public class sbmt extends httpservlet {
Private Static final long serialversionuid = 1l;
Public sbmt (){
Super ();
}
Public void destroy (){
Super. Destroy ();
}
Public void doget (httpservletrequest request, httpservletresponse response)
Throws servletexception, ioexception {
Response. setcontenttype ("text/html ");
Printwriter out = response. getwriter ();
Out
. Println ("<! Doctype HTML public \ "-// W3C // dtd html 4.01 transitional // en \"> ");
Out. println ("<HTML> ");
Out. println ("Out. println ("<body> ");
Out. Print ("this is ");
Out. Print (this. getclass ());
Out. println (", using the get method ");
Out. println ("</body> ");
Out. println ("Out. Flush ();
Out. Close ();
}
Public void dopost (httpservletrequest request, httpservletresponse response)
Throws servletexception, ioexception {
Httpsession session = request. getsession (false );
If (session = NULL)
{
Response. sendredirect ("error. jsp ");
Return;
}
String usernameone = (string) Session. getattribute ("username ");
String usernametwo = request. getparameter ("username ");
If (! Usernameone. Equals (usernametwo ))
{
Response. sendredirect ("error. jsp ");
Return;
}
Response. setcontenttype ("text/html; charset = GBK ");
Request. setattribute ("username", usernametwo );
If (usernametwo. Equals ("teacher "))
{
Response. sendredirect ("teacher. jsp ");
Return;
}
Else
{
Response. sendredirect ("error. jsp ");
Return;
}
}
}
}