1、源碼:javascript
一、Users.javacss
package com.login.entity; import java.io.Serializable; public class Users implements Serializable { /** * */ private static final long serialVersionUID = 1L; private Integer id; private String username; private String password; public Users() { super(); } public Users(Integer id, String username, String password) { super(); this.id = id; this.username = username; this.password = password; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
二、UsersController.javahtml
package com.login.controller; import java.util.HashMap; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import com.login.entity.Users; import com.login.service.UsersService; import com.login.util.MD5Util; @Controller @RequestMapping("/") public class UsersController { protected final Log logger = LogFactory.getLog(getClass()); @Resource private UsersService usersService; @RequestMapping("main") public String main() { return "main"; } @RequestMapping("login") public String login() { return "login"; /*HashMap<String, Object> users = new HashMap<String, Object>(); users.put("username",username.trim()); users.put("password",MD5Util.string2MD5(password.trim())); Users one=usersService.getUserByUsernameAndPassword(users); HttpSession session = request.getSession(); session.setAttribute("one",one); if(one==null){ model.addAttribute("error","用戶名或密碼錯誤!"); return "login"; }else{ return "redirect:/main"; }*/ } @RequestMapping("adminis") public String adminis(@Param("username") String username,@Param("password") String password,HttpServletRequest request,Model model) { HttpSession session = request.getSession(); session.setAttribute("username",username); session.setAttribute("password",password); if(username==null||username==""){ model.addAttribute("error","用戶名不能爲空!"); return "login"; }else if(password==null||password==""){ model.addAttribute("error","密碼不能爲空!"); return "logins"; } HashMap<String, Object> users = new HashMap<String, Object>(); users.put("username",username.trim()); users.put("password",MD5Util.string2MD5(password.trim())); Users user=usersService.getUserByUsernameAndPassword(users); session.setAttribute("user",user); if(user==null){ model.addAttribute("error","用戶名或密碼錯誤!"); return "logins"; }else{ return "redirect:/admin"; } } @RequestMapping("admin") public String admin() { return "main"; } @RequestMapping("logout") public String logout(HttpServletRequest request) { request.getSession().removeAttribute("user"); request.getSession().invalidate(); return "login"; } }
三、UsersService.javajava
package com.login.service; import java.util.ArrayList; import java.util.Map; import com.login.entity.Users; public interface UsersService { /** * 添加用戶信息 * @param param */ public void insertUsers(Map<String, Object> param); /** * 刪除用戶信息 * @param id */ public void deleteUsers(int id); /** * 修改用戶信息 * @param param */ public void updateUsers(Map<String, Object> param); /** * 查詢用戶信息(後臺) * @return List<Users> */ public ArrayList<Users> searchUsers(); /** * 根據用戶名稱查詢用戶信息(後臺) * @return List<Users> */ public ArrayList<Users> searchUsersByUsername(String username); /** * 根據編號查詢用戶信息 * @param id * @return Users */ public Users searchUsersById(int id); /** * 根據用戶名和密碼查詢用戶是否存在 * @param param * @return Users */ public Users getUserByUsernameAndPassword(Map<String, Object> param); }
四、UsersServiceImpl.javaweb
package com.login.service.impl; import java.util.ArrayList; import java.util.Map; import javax.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.login.entity.Users; import com.login.mapper.UsersMapper; import com.login.service.UsersService; @Service @Transactional // @Transactional表示該類被Spring做爲管理事務的類 public class UsersServiceImpl implements UsersService { @Resource private UsersMapper usersMapper; /** * 添加用戶信息 * * @param param */ @Override public void insertUsers(Map<String, Object> param) { usersMapper.insertUsers(param); } /** * 刪除用戶信息 * * @param id */ @Override public void deleteUsers(int id) { usersMapper.deleteUsers(id); } /** * 修改用戶信息 * * @param param */ @Override public void updateUsers(Map<String, Object> param) { usersMapper.updateUsers(param); } /** * 查詢用戶信息(後臺) * * @return List<Users> */ @Override public ArrayList<Users> searchUsers() { return usersMapper.searchUsers(); } /** * 根據用戶名稱查詢用戶信息(後臺) * * @return List<Users> */ @Override public ArrayList<Users> searchUsersByUsername(String username) { return usersMapper.searchUsersByUsername(username); } /** * 根據編號查詢用戶信息 * * @param id * @return Users */ @Override public Users searchUsersById(int id) { return usersMapper.searchUsersById(id); } /** * 根據用戶名和密碼查詢用戶是否存在 * * @param param * @return Users */ public Users getUserByUsernameAndPassword(Map<String, Object> param) { return usersMapper.getUserByUsernameAndPassword(param); } }
五、UsersMapper.javaspring
package com.login.mapper; import java.util.ArrayList; import java.util.Map; import com.login.entity.Users; public interface UsersMapper { /** * 添加用戶信息 * * @param param */ public void insertUsers(Map<String, Object> param); /** * 刪除用戶信息 * * @param id */ public void deleteUsers(int id); /** * 修改用戶信息 * * @param param */ public void updateUsers(Map<String, Object> param); /** * 查詢用戶信息(後臺) * * @return ArrayList<Users> */ public ArrayList<Users> searchUsers(); /** * 根據用戶名稱查詢用戶信息(後臺) * * @return ArrayList<Users> */ public ArrayList<Users> searchUsersByUsername(String username); /** * 根據編號查詢用戶信息 * * @param id * @return Users */ public Users searchUsersById(int id); /** * 根據用戶名和密碼查詢用戶是否存在 * * @param param * @return Users */ public Users getUserByUsernameAndPassword(Map<String, Object> param); }
六、UsersMapper.xmlsql
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.login.mapper.UsersMapper"> <insert id="insertUsers" parameterType="java.util.Map"> INSERT INTO tbl_Users ([username],[password]) VALUES (#{username},#{password}) <selectKey keyProperty="id" resultType="int" order="AFTER"> select @@identity </selectKey> </insert> <select id="deleteUsers" parameterType="java.lang.Integer"> delete from tbl_Users where id = #{id} </select> <update id="updateUsers" parameterType="com.login.entity.Users" statementType="PREPARED"> update tbl_Users <set> <if test="username != null">username = #{username},</if> <if test="password != null">password = #{password},</if> </set> where id = #{id} </update> <select id="searchUsers" parameterType="java.util.Map" resultType="com.login.entity.Users"> select * from tbl_Users </select> <select id="searchUsersByUsername" parameterType="java.lang.String" resultType="com.login.entity.Users"> select * from tbl_Users where username like '%${_parameter}%' </select> <select id="searchUsersById" parameterType="java.lang.Integer" resultType="com.login.entity.Users"> select * from tbl_Users where id = #{id} </select> <select id="getUserByUsernameAndPassword" parameterType="java.util.Map" resultType="com.login.entity.Users"> select * from tbl_Users where username=#{username} and password=#{password} </select> </mapper>
七、jdbc.properties數據庫
jdbc_driver=com.microsoft.sqlserver.jdbc.SQLServerDriver jdbc_url=jdbc:sqlserver://127.0.0.1:1433;DatabaseName=policestation jdbc_username=sa jdbc_password=systemadmin
七、applicationContext.xmlexpress
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <!-- 引入jdbc配置文件 --> <context:property-placeholder location="config/jdbc.properties" /> <!--配製數據源--> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="${jdbc_driver}"></property> <property name="url" value="${jdbc_url}"></property> <property name="username" value="${jdbc_username}"></property> <property name="password" value="${jdbc_password}"></property> </bean> <!-- 建立sqlSessionFactory,同時指定數據源 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="configLocation" value="/WEB-INF/mybatis-config.xml"/> <!-- 自動掃描mapper目錄, 省掉mybatis-config.xml裏的手工配置 --> <property name="mapperLocations"> <list> <value>classpath:com/login/mapper/*.xml</value> </list> </property> </bean> <!-- 經過掃描的模式,掃描目錄在com/login/mapper目錄下 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.login.mapper" /> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" /> </bean> <!-- (事務管理)--> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <!-- 使用annotation定義數據庫事務,這樣能夠在類或方法中直接使用@Transactional註解來聲明事務 --> <tx:annotation-driven transaction-manager="transactionManager" /> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="insert*" propagation="REQUIRED" /> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="approve" propagation="REQUIRED" /> <tx:method name="undo" propagation="REQUIRED" /> <tx:method name="load*" propagation="SUPPORTS" read-only="true" /> <tx:method name="get*" propagation="SUPPORTS" read-only="true" /> <tx:method name="search*" propagation="SUPPORTS" read-only="true" /> <tx:method name="*" propagation="SUPPORTS" read-only="true" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="serviceMethod" expression="execution(* com.login.service.*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod" /> </aop:config> <!-- 自動搜索註解路徑--> <context:component-scan base-package="com.login"></context:component-scan> </beans>
八、mybatis-config.xmlapache
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!--整合Spring的時候 只有 settings typeAliases mapper 三個屬性有用, 其他的要在spring總配置文件中會覆蓋 --> <settings> <!-- 全局映射器,是否啓用緩存 --> <setting name="cacheEnabled" value="false" /> <!-- 查詢時,關閉關聯對象即時加載以提升性能 --> <!-- 設置關聯對象加載的形態,此處爲按需加載字段(加載字段由SQL指 定),不會加載關聯表的全部字段,以提升性能 --> <setting name="aggressiveLazyLoading" value="false" /> <!-- 對於未知的SQL查詢,容許返回不一樣的結果集以達到通用的效果 --> <setting name="multipleResultSetsEnabled" value="true" /> <!-- 容許使用列標籤代替列名 --> <setting name="useColumnLabel" value="true" /> <!-- 容許使用自定義的主鍵值(好比由程序生成的UUID 32位編碼做爲鍵值),數據表的PK生成策略將被覆蓋 --> <setting name="useGeneratedKeys" value="true" /> <!-- 給予被嵌套的resultMap以字段-屬性的映射支持 --> <setting name="autoMappingBehavior" value="FULL" /> <!-- 對於批量更新操做緩存SQL以提升性能 --> <setting name="defaultExecutorType" value="BATCH" /> <!-- 數據庫超過25000秒仍未響應則超時 --> <setting name="defaultStatementTimeout" value="25000" /> </settings> </configuration>
九、spring-servlet.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> <!-- 自動掃描的包名 --> <context:component-scan base-package="com.login.controller"/> <!-- 默認的註解映射的支持 --> <mvc:annotation-driven /> <!-- 靜態資源映射 --> <mvc:resources mapping="/css/**" location="/WEB-INF/view/css/" cache-period="31556926"/> <mvc:resources mapping="/images/**" location="/WEB-INF/view/images/" cache-period="31556926"/> <mvc:resources mapping="/img/**" location="/WEB-INF/view/img/" cache-period="31556926"/> <mvc:resources mapping="/js/**" location="/WEB-INF/view/js/" cache-period="31556926"/> <mvc:resources mapping="/m_css/**" location="/WEB-INF/view/manager/css/" cache-period="31556926"/> <mvc:resources mapping="/m_images/**" location="/WEB-INF/view/manager/images/" cache-period="31556926"/> <mvc:resources mapping="/datePicker/**" location="/WEB-INF/view/manager/My97DatePicker/" cache-period="31556926"/> <mvc:resources mapping="/dtree/**" location="/WEB-INF/view/dtree/" cache-period="31556926"/> <mvc:resources mapping="/ztree/**" location="/WEB-INF/view/zTree_v3/" cache-period="31556926"/> <mvc:resources mapping="/FCKeditor/**" location="/FCKeditor/" cache-period="31556926"/> <mvc:resources mapping="/UserFiles/**" location="/UserFiles/" cache-period="31556926"/> <mvc:resources mapping="/upload/**" location="/upload/" cache-period="31556926"/> <mvc:resources mapping="/uploadFriendly/**" location="/uploadFriendly/" cache-period="31556926"/> <mvc:resources mapping="/uploadAdvert/**" location="/uploadAdvert/" cache-period="31556926"/> <mvc:resources mapping="/uploadNotice/**" location="/uploadNotice/" cache-period="31556926"/> <mvc:resources mapping="/tool/**" location="/tool/" cache-period="31556926"/> <mvc:resources mapping="/loginImg/**" location="/WEB-INF/view/manager/login/images/" cache-period="31556926"/> <!-- 對模型視圖添加先後綴 --> <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/" /> <property name="suffix" value=".jsp" /> </bean> <!-- file upload --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="-1" /><!-- 字節單位 --> <property name="maxInMemorySize" value="2048" /><!-- 2M --> <property name="defaultEncoding" value="UTF-8" /> </bean> </beans>
十、web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>錯誤跳轉頁面</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <display-name>session銷燬時間(分鐘)</display-name> <session-config> <session-timeout>30</session-timeout> </session-config> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <display-name>Spring字符集過濾器</display-name> <filter> <filter-name>encoding</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
十一、index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% 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 'index.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"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> This is my JSP page. <br> <a href="login.html">管理登陸</a> </body> </html>
十二、login.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ page import="com.login.entity.Users"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>用戶登陸</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <style> body{margin:0; padding:0; font-size:9pt;} #login{margin:auto; width:975px; height:368px; margin-top:120px;} #top_left{width:691px; height:89px; float:left;} #top_left img {margin-left:33px;} #top_center{width:248px; height:89px; background:url(loginImg/login_05.gif); float:left;} #center_left{width:691px; height:190px; background:url(loginImg/login_09.jpg); float:left;} #center_middle{width:248px; height:190px; float:left; background:url(loginImg/login_13.gif) repeat-y;} #center_right{width:36px; height:190px; float:right; background:url(loginImg/login_11.gif);} #down_left{width:691px; height:89px; float:left; margin-top:15px;} #down_center{width:248px; height:89px; background:url(loginImg/login_16.gif); float:left;} #inf{width:691px; height:38px; background:url(loginImg/login_18.gif) no-repeat; } .inf_text{display:block; width:100px; height:20px; font-size:16px; font-weight:bolder; color:#fff; margin-left:17px; margin-top:12px; float:left;} .copyright{display:block; float:left; margin-left:17px; margin-top:15px;} #message{text-align:center;color:red;} #user{ margin-left:40px; margin-top:15px;} #password{margin-left:40px; margin-top:25px; height:25px;} input{width:120px; height:18px; border:solid 1px #aca7a7; font-size:9pt;} #btn{margin-left:30px; margin-top:40px;height:25px; margin-right:28px; text-align:center;} #btn a{display:block; line-height:25px; background: url(loginImg/bt_bg.gif); border: solid 1px #b6b6b6; width:65px; float:left; margin-left:15px; text-decoration:none; color:#000;} #btn input{display:block;height:25px; line-height:22px; background: url(loginImg/bt_bg.gif); border: solid 1px #b6b6b6; width:65px; float:left; margin-left:2px; text-decoration:none; color:#000;} </style> <script type="text/javascript"> function show(){ if(document.getElementById("name").value==""){ document.getElementById("showname").innerHTML="用戶名不能爲空!"; document.getElementById("name").focus(); return false; }else if(document.getElementById("pwd").value==""){ document.getElementById("showname").innerHTML="密碼不能爲空!"; document.getElementById("pwd").focus(); return false; }else{ return true; } </script> </head> <body> <form action="adminis.html" method="post" name="myform"> <div id="login"> <div id="top"> <div id="top_left"><img src="loginImg/login_03.gif"/></div> <div id="top_center"></div> </div> <div id="center"> <div id="center_left"></div> <div id="center_middle"> <div id="message">${error}<span id="showname" style="display:inline;"></span></div> <div id="user">用 戶:<input type="text" name="username" onblur="show()" id="name"/></div> <div id="password">密 碼:<input type="password" name="password" onblur="show()" id="pwd"/></div> <div id="btn"><a href="javascript:document.myform.submit();">登 錄</a><a href="javascript:document.myform.reset();">清 空</a></div> </div> <div id="center_right"></div> </div> <div id="down"> <div id="down_left"> <div id="inf"><span class="inf_text">版本信息</span><span class="copyright">信息管理系統 2015 v1.0</span><span class="copyright" style="color:red;">請在IE10如下版本中使用後臺功能</span></div> </div> <div id="down_center"></div> </div> </div> </form> </body> </html>
1三、logins.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ page import="com.login.entity.Users"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>用戶登陸</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <style> body{margin:0; padding:0; font-size:9pt;} #login{margin:auto; width:975px; height:368px; margin-top:120px;} #top_left{width:691px; height:89px; float:left;} #top_left img {margin-left:33px;} #top_center{width:248px; height:89px; background:url(loginImg/login_05.gif); float:left;} #center_left{width:691px; height:190px; background:url(loginImg/login_09.jpg); float:left;} #center_middle{width:248px; height:190px; float:left; background:url(loginImg/login_13.gif) repeat-y;} #center_right{width:36px; height:190px; float:right; background:url(loginImg/login_11.gif);} #down_left{width:691px; height:89px; float:left; margin-top:15px;} #down_center{width:248px; height:89px; background:url(loginImg/login_16.gif); float:left;} #inf{width:691px; height:38px; background:url(loginImg/login_18.gif) no-repeat; } .inf_text{display:block; width:100px; height:20px; font-size:16px; font-weight:bolder; color:#fff; margin-left:17px; margin-top:12px; float:left;} .copyright{display:block; float:left; margin-left:17px; margin-top:15px;} #message{text-align:center;color:red;} #user{ margin-left:40px; margin-top:15px;} #password{margin-left:40px; margin-top:25px; height:25px;} input{width:120px; height:18px; border:solid 1px #aca7a7; font-size:9pt;} #btn{margin-left:30px; margin-top:40px;height:25px; margin-right:28px; text-align:center;} #btn a{display:block; line-height:25px; background: url(loginImg/bt_bg.gif); border: solid 1px #b6b6b6; width:65px; float:left; margin-left:15px; text-decoration:none; color:#000;} #btn input{display:block;height:25px; line-height:22px; background: url(loginImg/bt_bg.gif); border: solid 1px #b6b6b6; width:65px; float:left; margin-left:2px; text-decoration:none; color:#000;} </style> <script type="text/javascript"> function show(){ if(document.getElementById("name").value==""){ document.getElementById("showname").innerHTML="用戶名不能爲空!"; document.getElementById("name").focus(); return false; }else if(document.getElementById("pwd").value==""){ document.getElementById("showname").innerHTML="密碼不能爲空!"; document.getElementById("pwd").focus(); return false; }else{ return true; } </script> </head> <body> <form action="adminis.html" method="post" name="myform"> <div id="login"> <div id="top"> <div id="top_left"><img src="loginImg/login_03.gif"/></div> <div id="top_center"></div> </div> <div id="center"> <div id="center_left"></div> <div id="center_middle"> <div id="message">${error}<span id="showname" style="display:inline;"></span></div> <div id="user">用 戶:<input type="text" name="username" value="<%=(String)session.getAttribute("username") %>" onblur="show()" id="name"/></div> <div id="password">密 碼:<input type="password" name="password" value="<%=(String)session.getAttribute("password") %>" onblur="show()" id="pwd"/></div> <div id="btn"><a href="javascript:document.myform.submit();">登 錄</a><a href="login.html">清 空</a></div> </div> <div id="center_right"></div> </div> <div id="down"> <div id="down_left"> <div id="inf"><span class="inf_text">版本信息</span><span class="copyright">信息管理系統 2015 v1.0</span><span class="copyright" style="color:red;">請在IE10如下版本中使用後臺功能</span></div> </div> <div id="down_center"></div> </div> </div> </form> </body> </html>
1四、main.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ page import="com.login.entity.Users"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <% Users user=(Users)session.getAttribute("user"); %> <head> <title>My JSP 'index.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"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> This is my JSP page. <br> 歡迎您<%=user.getUsername() %> </body> </html>
2、lib下項目支持的驅動包(如下是須要的jar包,文件太大,沒法上傳請看圖片,按照下面的版本下載就能夠。)
3、須要的數據庫文件可自行設計建庫。