JSF + Spring + Hibernate development Sample __js

Source: Internet
Author: User
Tags exception handling stub

The following is a use case diagram where users can do the following: login, browse, register, modify, delete, exit


Create user Project


Add JSF framework, Spring Framework, Hibernate framework

The JSF framework here uses MyFaces1.0.9 in MyEclipse, and when you eject the dialog box that adds the Java package, select No, and if you choose Yes, you will find that the JSP page does not display the problem in Tomcat, but if you change the resin3, please do not use sun JSF, because the next integration part must use Myfaces, of course, if you have friends who will integrate Sun JSF will not reluctantly, and please teach me how to integrate.

When you add the spring framework, select all the options, which one should be used, and I can't tell you what to do. After the creation, you need to configure the Web.xml file to include the following:

<servlet>

<servlet-name>context</servlet-name>

<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>

<load-on-startup>1</load-on-startup>

</servlet>


<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>/WEB-INF/applicationContext.xml</param-value>

</context-param>


When you finish adding hibernate, remember to copy the JDBC file to the Lib directory


Use three-tier structure: WEB layer, MODEL layer, and DATA layer


Start MySQL and create the users table

CREATE TABLE ' user ' (

' id ' int (one) not NULL auto_increment,

' username ' varchar not NULL default ',

' Password ' varchar not NULL default ',

PRIMARY KEY (' id ')

)


New three packages, respectively: Com.web, Com.model, Com.data


The following packages are included in the Com.web package:

Com.web.bo, Com.web.vo


The following packages are included in the Com.model package:

Com.model.service, Com.model.service.impl, com.model.exception


The Com.data package contains the following packages:

Com.data.dao, Com.data.dao.impl


Packet Com.web.bo, used to store the image of the mapped Bo (business) layer

Packet Com.web.vo, used to store the image of the VO (business) layer after mapping


Packet Com.model.service, used to store the interface of the service layer's image

Packet Com.model.service.impl, an instance of a pair of interface for storing service (services) layers

Package com.model.exception, for storing custom exception handling classes


Packet Com.data.dao, used to store the interface of the DAO (data access) layer to the image

Packet Com.data.dao.impl, an instance of the image interface used to hold the DAO (data access) layer


Configure the table to map after the hibernate is completed and save the mapping file to the COM.WEB.BO package


Create an exception-handling class Userexception.java, which reads as follows:

public class Userexception extends Exception {

Public Userexception () {

Super ();

}

Public userexception (String msg) {

Super (MSG);

}

Public userexception (String msg, throwable cause) {

Super (MSG, cause);

}

}


To create a user image using the Data browsing tool


Create JSF Binding Classes Userbasebean and UserBean, Userbasebean is the base class for UserBean

The contents of Userbasebean are as follows:

Package com.web.vo;

public class Userbasebean {

}


The contents of UserBean are as follows:

Package com.web.vo;

Import com.model.exception.UserException;

Import Com.web.bo.User;


public class UserBean extends Userbasebean {


Private user User=new user ();

Public User GetUser () {

return user;

}

public void SetUser (user user) {

This.user = user;

}

Logon events

Public String loginaction () {

return null;

}

Exit events

Public String logoutaction () {

return null;

}

Registering events

Public String registeraction () {

return null;

}

Delete Event

Public String deleteaction () {

return null;

}

Edit Events

Public String editaction () {

return null;

}

Browsing Events

Public String browseaction () {

return null;

}

}


Create the Iuserservice interface, which reads as follows:

The function of this interface is to call her by the UI layer, and she calls the data layer to access the database processing data.

Package com.model.service;

Import java.util.List;

Import Com.web.bo.User;

Import com.model.exception.UserException;

Public interface Iuserservice {

Public User Login (String username,string password) throws userexception;

public Boolean logout () throws userexception;

Public boolean register (user user) throws userexception;

public boolean Delete (Integer uid) throws userexception;

Public boolean edit (user user) throws userexception;

Public List browse () throws userexception;

}

The above method is the business logic, from the word should be able to see what is the use of


Create the implementation Userserviceimpl class for the Iuserservice interface, which reads as follows:

Package Com.model.service.impl;

Import java.util.List;

Import Com.model.exception.IUserService;

Import com.model.exception.UserException;

Import Com.web.bo.User;


public class Userserviceimpl implements Iuserservice {


Public User Login (string username, string password) throws Userexception {

TODO auto-generated Method Stub

return null;

}

public Boolean logout () throws Userexception {

TODO auto-generated Method Stub

return false;

}

Public boolean register (user user) throws Userexception {

TODO auto-generated Method Stub

return false;

}

public boolean Delete (Integer uid) throws Userexception {

TODO auto-generated Method Stub

return false;

}

Public boolean edit (user user) throws Userexception {

TODO auto-generated Method Stub

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.