Summary of some questions about JSP

Source: Internet
Author: User

Who can help me see what the problem is? Thank you!
Register.html:
Copy codeThe 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 codeThe 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 codeThe 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 ("<HEAD> <TITLE> A Servlet </TITLE> </HEAD> ");
Out. println ("<BODY> ");
Out. print ("This is ");
Out. print (this. getClass ());
Out. println (", using the GET method ");
Out. println ("</BODY> ");
Out. println ("</HTML> ");
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;
}
}
}
}

Related Article

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.