STRUTS2 Project Integration Personnel Management System (IV)

Source: Internet
Author: User

Brief introduction

Today finishing is a combination of Struts2 do a personnel query management system. The development process has not been written too much. Overall project development is relatively simple, based on the template to modify the page, write the action class

Development Prelude
Development Prelude 1. Import people to manage Project 2. Set up Database, table drop DATABSE if exists struts;create database alice;create user [email protected] identified by ' 123 '; Add user grant all on struts.* to [email protected]//authorized Oracle One data represents a service, there are many users in this library, each user has a table space set character_set_client = GBK ; # User table CREATE TABLE S_user (UserID INT NOT NULL auto_increment, #主键IDuserName varchar () NULL, #用户姓名logonName varchar (5 0) NULL, #登录名logonPwd varchar () NULL, #密码 #sex varchar (ten) NULL, #性别 (ex: Male, female) birthday varchar () NULL, #出 Raw date education varchar () NULL, #学历 (e.g. graduate, undergraduate, specialist, high school) telephone varchar () NULL, #电话 interest varchar () NULL, #兴趣爱好 (For example: sports, tourism, Shopping) path varchar ($) NULL, #上传路径 (path path) filename varchar (+) NULL, #上传文件名称 (file name) remark varchar (NUL) L, #备注PRIMARY KEY (UserID)) Target function: Build development environment Struts2+javabean+dao+dbcp+dbutils+mysql importing jar packages and configuration files web.xmlindex.jsp/ Index.html;<filter> Join the core controller StrutsPrepareAndExecuteFilterstruts.xmldbcpconfig.properties
Service Layer/dao Layer implementation
1. Define the business interface (based on functional requirements) Businessserviceuser login (String logonname, string logonpwd); List<user> findallusers (); List<user> findusersbycondition (String userName, string sex,string education,string filename), void AddUser (User user); void edituser (user user); User Finduserbyid (Integer userId), void Deluser (user user), 2. Background business code implementation, test Userdaovoid Save (user user); void del (user user); void update (user user); List<user> finduserbycoditions (Integer userid,string logonname,string logonpwd,string sex,String Education, String filename); User Finduserbyusernamepassword (String logonname, string logonpwd); List<user> findallusers (); List<user> findusersbycondition (String userName, string sex,string education,string filename); User Finduserbyid (Integer userId); 3. Add implementation class USERDAOMYSQLIMPL1). The delete/update user determines whether the incoming user and user ID is empty if NULL throws an invalid parameter exception 2). List<user> finduserbycoditions (Integer userid,string username,string sex,string Education, String filename); Determines whether the passed in parameter is empty, if all null represents the query all at least one parameter is not empty List<object> Parameters = new Arraylist<object> (), if (userId! = null) {Sb.append ("and userid=?")} if (Stringutils.isnotblank (username)) {sb.apppend ("and username like?")} if (Stringutils.isnotblank (filename)) {if ("true". Equals (filename)) {sb.append ("and filename is not null");} else { Sb.append ("and filename is null");}} 4. Business implementation class Businessserviceimplprivate Userdao DAO = new Userdaomysqlimpl (); 5. Testing the business implementation class

function implementation
First, login function 1. Retrofit login page login.jsp# Modify theme: Struts.ui.theme=simple<s:form action= "Userlogin" >logonname/logonpwd/submit/reset2. Struts-user.xml<action name= "Userlogin" > Redirected to the page after login home.jsp, error goes to LOGIN.JSP3. Useraction Class 1). Use Modeldrivern to encapsulate User Data 2). Configure the Spring container in Applicationcontext.xml to inject the business implementation Class 3). Establish user logon method call business method get user, if Add error action message for empty, return input view otherwise set session field, Returns SUCCESS4. top.jsp, modify user name: <s:property value= "#session. User.usernaname" > II, query all users 1. Transform Left.jsp<s:url action= "findalluser" namespace= "/user" var= "Findalluserurl" >2. Add <action anem= "Findalluser" > Nodes <result> go to LIST.JSP3. Retrofit List.jsp<s:iterator value= "users" var= "user" >/username/gender/Phone/Education 4. Query user transformation, establish a finduserbyusernamepassword (); third, according to the conditions of inquiry 1. List.jsp--><s:form action= "listbycondition" namespace= "/user" ><s:textfield> user name/gender <s:select List= "#{}" "headerkey=" "education/whether to upload education submit2. Struts-user.xml configuration file <action name= "Listbycondition" >3. Retrofit Useractionlistbycondition (); iv. Add user 1. list.jsp Modify Submit <s:submit type= "button" &Gt;2. add.jsp Modify import Struts Tag library <s:form action= "AddUser" enctype= "" > Login/Password/user name/gender <s:radio list= "#{}" value={' Male '} > Education/Date of birth/telephone/hobbies <s:checkboxlist list= "{'}"/CV <s:file>3. Add <action> node, redirect action to Redirectaction--->findalluser4. Useraction---addUser () isupload/interests[]/upload/uploadfilename/1). The data is already encapsulated in the user object, in addition to the hobby and CV store path 2). Judge interests is not empty and the length is greater than 0, traverse interest, splicing hobby, separates. The stitched string is set to User 3). Get the real path and set the path to User 4). Use Tokenhelper.generateguid () to generate a new file name, set to User 5). Fileutils Copy to the destination fileutils copy to 6). Call the business method and add the user object to the database v. Edit function 1. List.jsp<s:a namespace= "/user" action= "findoneuser" ><s:param name= "UserID" value= "<s:property value=" # User.userid ">2. Add the Action node Name= "Findoneuser" 3. Useraction---->findoneuser () calls the Business method Findoneuser () and presses the user into the stack top return success;4. edit.jsp Page Hobbies value= "%{interest.split (', ')}" resume download re-upload 5. <action> Add download action <result type= "stream" ><param name= "InputName" ><param name= "ContentType" >application/octet-stream</param><param name= "Contentdisposition" >attachment;filename=${}6. Add the download method to the action class by querying the user with the ID to get the path file associated with the real path in the user, creating Stream object 7. The action node in T adds Edituser action 8. Add Edituser () method to the Useraction class if the upload is not empty, re-upload otherwise the user does not choose to re-upload, keep the original file name and pathname call business Method Edituser () Method 9. View features list.jsp,<s:a namespace= "/user" action= "Viewuser" >viewuser action method view.jsp, change to Struts label 10. Remove feature list.jsp11. Problem with null pointer exception if the file is not empty, upload only six, the interceptor to determine the login Logoncheckinterceptor implementation Methodfilterinterceptor from the session to get the user, Determine if empty, define <interceptors><interceptor name= "Logoncheckinterceptor" ><param name= "ExcludeMethods" > Userlogin</param></interceptor><interceptor-stack name= "Mydefault" > Defaultstacklogoncheckinterceptor<global-results>

Struts2 Project Integration Personnel Management System (IV)

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.