JSP Nineth lesson: Online Shop Backstage--Background related page design

Source: Internet
Author: User

First, the background head page design

1, head.jsp main code:

%@ page language= "java" import= "java.util.*,mybean.*" pageencoding= "Utf-8"%>
<%
Admin admin= (Admin) session.getattribute ("admin");
if (admin!=null)
{
%>

Current User: <%=admin.getname ()%>

<a style= "COLOR: #fff"
href= "Admin_update.jsp"
target=blank> Change Password </A>

<a style= "COLOR: #fff"
href= "exit1.jsp" target=_blank> exit system </A>

<%}%>



2. Change Password design

(1) Change Password page admin_update.jsp (the same as the login page, the difference is that the user name cannot be changed, you can change the password, action to admin_doupdate.jsp)

Main code:

<%@ page language= "java" import= "mybean.*,java.util.*" pageencoding= "UTF-8"%>
<%
Admin admin= (Admin) session.getattribute ("admin");
if (admin!=null)
{
%>

<form name= "Form1" action= "admin_doupdate.jsp" method= "POST" >
<input type= "hidden" name= "aid" value= "<%=admin.getaid ()%>"/>

User name: <input type= "text" value= "<%=admin.getname ()%>" Name=name readonly= "OK" >

Password: <input type=password maxlength=30 size=24 value= "" name=pass>

。。。。

(2) Handling change information admin_doupdate.jsp

<%@ page language= "java" import= "mybean.*,java.util.*" pageencoding= "UTF-8"%>

<%
String name = Request.getparameter ("name");
String pwd = request.getparameter ("Pass");
String aid=request.getparameter ("aid");

Admindao dao=new Admindao ();
Create the Admin object to deposit values

Admin admin=new admin ();
Admin.setaid (Integer.parseint (aid));
Admin.setname (name);
Admin.setpassword (PWD);

if (dao.update (admin))
{
Session.setattribute ("admin", admin); Save the changed admin in session

Response.sendredirect ("index.jsp");
}
%>

(3) Change password in DAO database, Admin.update (Admin) method to implement Change password function

public boolean update (admin admin) {
Connection Conn=null;
PreparedStatement Ps=null;
Boolean flag=false;

String sql= "Update admin set password=?" where aid=? ";

String classname= "Com.microsoft.sqlserver.jdbc.SQLServerDriver";
String user= "shopping";
String password= "shopping";
String url= "Jdbc:sqlserver://localhost:1433;database=ebuy";

try {
Class.forName (ClassName);
Conn=drivermanager.getconnection (URL, user, password);
Ps=conn.preparestatement (SQL);

Ps.setstring (1,admin.getpassword ());
Ps.setint (2, Admin.getaid ());
int n=ps.executeupdate ();
if (n>=1) {
Flag=true;
}

} catch (Exception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}

try {

if (ps!=null)
Ps.close ();

if (conn!=null)
Conn.close ();

} catch (Exception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}

return flag;
}

2. Logout User exit1.jsp

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>
<%
Session.invalidate ();
Response.sendredirect ("login.htm");
%>

Second, left menu page menu.html

<a class=menuchild href= "good_view.jsp" target=main> merchandise show </A>

<a class=menuchild href= "good_add.jsp" target=main> Add products </A>

<a class=menuchild href= "admin_update.jsp" target=blank> Change Password </A>

<a Class=menuchild
(Confirm (' Are you sure you want to exit? ')) return true; else return false; "
href= "Exit1.jsp"
Target=_top> Exit System </A>

Third, right default page design

1. Database Add registration Time (add_time default value getdate ()), number of accesses (count default 0) field

2. Javabean--admin Add String add_time,int count and related methods

3. main.jsp page

<%@ page language= "java" import= "java.util.*" pageencoding= "Utf-8"%>
<% @page import= "mybean.*"%>
<% @page import= "mybean.util.*"%>
<%
Admin admin= (Admin) session.getattribute ("admin");
if (admin!=null)
{
Date Date=new date ();
String datestr= (1900+date.getyear ()) + "year" + (Date.getmonth () +1) + "month" +date.getdate () + "Day" +date.gethours () + ":" + Date.getminutes () + ":" +date.getseconds ();
%>

<p> This login time:<%=datestr%></p>

<p> User name: <%=admin.getname ()%></p>

<p> Registration Time: <%=admin.getadd_time ()%></p>

<p> Number of Login: <%=admin.getcount ()%></p>

4, dologin.jsp page, add the function database "login number +1", required to show it in main.jsp

(1) dologin.jsp Add code (different color parts)

<%@ page language= "java" import= "mybean.*,java.util.*" pageencoding= "UTF-8"%>

<%
String name = Request.getparameter ("name");
String pwd = request.getparameter ("Pass");
Admindao dao=new Admindao ();
Admin admin=dao.login (name, PWD);



if (Admin.getname ()!=null)

Correct the error, before using Admin!=null, there is a problem do not enter a user name and password can log in
{
Dao.count (Admin.getaid ());
Response.setheader ("Refresh", "2;url=index.jsp");
Admin.setcount (Admin.getcount () +1);
Session.setattribute ("admin", admin);
}
else {
OUT.PRINTLN ("Login Failed");
Response.setheader ("Refresh", "2;url=login.htm");
}
%>

(2) DAO Write access number plus 1 method admin.count (AID)

Public boolean count (int aid) {
  connection conn=null;
  preparedstatement Ps=null;
  boolean Flag=false;
  
  string sql= "Update admin set count=count+1 where aid=?";
  
  string classname= "Com.microsoft.sqlserver.jdbc.SQLServerDriver";
  string user= "shopping";
  string password= "shopping";
  string url= "Jdbc:sqlserver://localhost:1433;database=ebuy";
  
  try {
   class.forname (className);
   conn=drivermanager.getconnection (URL, user, password);
   ps=conn.preparestatement (SQL);

Ps.setint (1, aid);
int n=ps.executeupdate ();
if (n>=1) {
Flag=true;
}

} catch (Exception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}

try {

if (ps!=null)
Ps.close ();

if (conn!=null)
Conn.close ();

} catch (Exception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}

return flag;

}

Iv. realize the management of front-desk user function



This article is from the "Learn Without thinking" blog, please be sure to keep this source http://dyzyxy.blog.51cto.com/944775/1625824

JSP Nineth lesson: Online Shop Backstage--Background related page design

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.