日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

案例46-crm练习客户登录

發布時間:2023/12/20 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 案例46-crm练习客户登录 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1 login.jsp代碼

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%> <%@ taglib uri="/struts-tags" prefix="s"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/frameset.dtd"> <HTML xmlns="http://www.w3.org/1999/xhtml"> <HEAD> <META http-equiv=Content-Type content="text/html; charset=utf-8"> <STYLE type=text/css> BODY {FONT-SIZE: 12px; COLOR: #ffffff; FONT-FAMILY: 宋體 } TD {FONT-SIZE: 12px; COLOR: #ffffff; FONT-FAMILY: 宋體 } </STYLE><META content="MSHTML 6.00.6000.16809" name=GENERATOR></HEAD> <BODY> <FORM id=form1 name=form1 action="${pageContext.request.contextPath }/UserAction_login" method=post><DIV id=UpdatePanel1> <DIV id=div1 style="LEFT: 0px; POSITION: absolute; TOP: 0px; BACKGROUND-COLOR: #0066ff"></DIV> <DIV id=div2 style="LEFT: 0px; POSITION: absolute; TOP: 0px; BACKGROUND-COLOR: #0066ff"></DIV><DIV>&nbsp;&nbsp; </DIV> <DIV> <TABLE cellSpacing=0 cellPadding=0 width=900 align=center border=0><TBODY><TR><TD style="HEIGHT: 105px"><IMG src="images/login_1.gif" border=0></TD></TR><TR><TD background=images/login_2.jpg height=300><TABLE height=300 cellPadding=0 width=900 border=0><TBODY><TR><TD colSpan=2 height=35></TD></TR><TR><TD width=360></TD><TD><TABLE cellSpacing=0 cellPadding=2 border=0><TBODY><TR><TD style="HEIGHT: 28px" width=80>登 錄 名:</TD><TD style="HEIGHT: 28px" width=150><INPUT id=txtName style="WIDTH: 130px" name="user_code"></TD><TD style="HEIGHT: 28px" width=370><SPAN id=RequiredFieldValidator3 style="FONT-WEIGHT: bold; VISIBILITY: hidden; COLOR: white">請輸入登錄名</SPAN></TD></TR><TR><TD style="HEIGHT: 28px">登錄密碼:</TD><TD style="HEIGHT: 28px"><INPUT id=txtPwd style="WIDTH: 130px" type=password name="user_password"></TD><TD style="HEIGHT: 28px"><SPAN id=RequiredFieldValidator4 style="FONT-WEIGHT: bold; VISIBILITY: hidden; COLOR: white">請輸入密碼</SPAN></TD></TR><TR><TD style="HEIGHT: 28px">驗證碼:</TD><TD style="HEIGHT: 28px"><INPUT id=txtcode style="WIDTH: 130px" name=txtcode></TD><TD style="HEIGHT: 28px">&nbsp;</TD></TR><TR><TD style="HEIGHT: 18px"></TD><TD style="HEIGHT: 18px"><span style="color:red"><s:property value="exception.message"/></span></TD><TD style="HEIGHT: 18px"></TD></TR><TR><TD></TD><TD><INPUT id=btn style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" type=image src="images/login_button.gif" name=btn> </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR><TR><TD><IMG src="images/login_3.jpg" border=0></TD></TR></TBODY></TABLE></DIV></DIV> </FORM> <s:debug></s:debug> </BODY></HTML>

2 UserAction

package www.test.web.action;import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ModelDriven;import www.test.domain.User; import www.test.service.UserService; import www.test.service.impl.UserServiceImpl;public class UserAction extends ActionSupport implements ModelDriven<User> {private User user = new User();private UserService us = new UserServiceImpl();public String login() throws Exception {//1 調用Service 執行登陸操作User u = us.login(user);//2 將返回的User對象放入session域作為登陸標識ActionContext.getContext().getSession().put("user", u);//3 重定向到項目的首頁return "toHome";}@Overridepublic User getModel() {return user;} }

3 UserServiceImpl

package www.test.service.impl;import www.test.dao.UserDao; import www.test.dao.impl.UserDaoImpl; import www.test.domain.User; import www.test.service.UserService; import www.test.utils.HibernateUtils;public class UserServiceImpl implements UserService {private UserDao ud = new UserDaoImpl();@Overridepublic User login(User user) {//打開事務 HibernateUtils.getCurrentSession().beginTransaction();//1.調用Dao根據登陸名稱查詢User對象User existU = ud .getByUserCode(user.getUser_code());//提交事務 HibernateUtils.getCurrentSession().getTransaction().commit();if(existU==null){//獲得不到=>拋出異常提示用戶名不存在throw new RuntimeException("用戶名不存在!");}//2 比對密碼是否一致if(!existU.getUser_password().equals(user.getUser_password())){//不一致=>拋出異常提示密碼錯誤throw new RuntimeException("密碼錯誤!");}//3 將數據庫查詢的User返回return existU;} }

4 UserDaoImpl

package www.test.dao.impl;import org.hibernate.Query; import org.hibernate.Session;import www.test.dao.UserDao; import www.test.domain.User; import www.test.utils.HibernateUtils;public class UserDaoImpl implements UserDao {@Overridepublic User getByUserCode(String user_code) {//HQL查詢//1.獲得SessionSession session = HibernateUtils.getCurrentSession();//2 書寫HQLString hql = "from User where user_code = ? ";//3 創建查詢對象Query query = session.createQuery(hql);//4 設置參數query.setParameter(0, user_code);//5 執行查詢User u = (User) query.uniqueResult();return u;}}

5 struts.xml

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""http://struts.apache.org/dtds/struts-2.3.dtd"> <struts><!-- 指定struts2是否以開發模式運行1.熱加載主配置.(不需要重啟即可生效)2.提供更多錯誤信息輸出,方便開發時的調試--><constant name="struts.devMode" value="true"></constant><package name="crm" namespace="/" extends="struts-default" ><global-exception-mappings><!-- 如果出現名為java.lang.RuntimeException的異常,就跳轉到名為error的結果 --><exception-mapping result="error" exception="java.lang.RuntimeException"></exception-mapping></global-exception-mappings><action name="CustomerAction_*" class="www.test.web.action.CustomerAction" method="{1}" ><result name="list" >/jsp/customer/list.jsp</result><result name="toList" type="redirectAction"><param name="actionName">CustomerAction_list</param><param name="namespace">/</param></result></action><action name="UserAction_*" class="www.test.web.action.UserAction" method="{1}" ><result name="toHome" type="redirect">/index.htm</result><result name="error" type="dispatcher">/login.jsp</result></action></package> </struts>

?

轉載于:https://www.cnblogs.com/jepson6669/p/8530926.html

總結

以上是生活随笔為你收集整理的案例46-crm练习客户登录的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。