Eclipse use maven S3

Source: Internet
Author: User
Tags aop

"LJ?" Dragon "User Control layer

"RELATED LINKS" user business Logic Layer: http://www.cnblogs.com/anstoner/p/6398637.html

1. New WebApp MAVEN Project 1.1 writing pom.xml configuration file
<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" ><modelversion >4.0.0</modelversion><groupid>cn.anstone</groupid><artifactid>user-web</ Artifactid><packaging>war</packaging><version>0.0.1-snapshot</version><name> User-web Maven webapp</name><url>http://maven.apache.org</url><dependencies><!-- Configure local dependency--><dependency><groupid>cn.anstone</groupid><artifactid>user-services</ artifactid><version>0.0.1-snapshot</version></dependency><!--Add servlet support-->< Dependency><groupid>javax.servlet</groupid><artifactid>javax.servlet-api</artifactid ><version>3.1.0</version></dependency><dependency><groupid>javax.servlet.jsp </groupid><artifactid>javax.servlet.jsp-api</artifactid><version>2.3.1</version></dependency><!-- Add JTL Support--><dependency><groupid>javax.servlet</groupid><artifactid>jstl</ artifactid><version>1.2</version></dependency><!--Add Spring support--><dependency> <groupid>org.springframework</groupid><artifactid>spring-core</artifactid><version >4.1.7.release</version></dependency><dependency><groupid>org.springframework</ groupid><artifactid>spring-beans</artifactid><version>4.1.7.release</version></ Dependency><dependency><groupid>org.springframework</groupid><artifactid>spring-tx </artifactId><version>4.1.7.RELEASE</version></dependency><dependency>< Groupid>org.springframework</groupid><artifactid>spring-context</artifactid><version >4.1.7.release</versioN></dependency><dependency><groupid>org.springframework</groupid><artifactid> spring-context-support</artifactid><version>4.1.7.release</version></dependency>< Dependency><groupid>org.springframework</groupid><artifactid>spring-web</artifactid ><version>4.1.7.RELEASE</version></dependency><dependency><groupId> org.springframework</groupid><artifactid>spring-webmvc</artifactid><version>4.1.7. Release</version></dependency><dependency><groupid>junit</groupid><artifactid >junit</artifactid><version>4.12</version><scope>test</scope></dependency ></dependencies><build><finalname>user-web</finalname></build></project >

1.2 Writing the User control layer method/user-web/src/main/java/cn/anstone/controller/usercontroller.java
Package Cn.anstone.controller;import Javax.servlet.http.httpservletrequest;import javax.servlet.http.HttpSession; Import Org.springframework.beans.factory.annotation.autowired;import Org.springframework.stereotype.Controller; Import Org.springframework.web.bind.annotation.requestmapping;import Cn.anstone.entity.user;import cn.anstone.services.userservice;/*** Description: User Control Layer Method * * @author anstone* * @Date Feb, 2017*/@Controller @requestmapping ("/ User ") public class Usercontroller {@Autowiredprivate userservice userservice, @RequestMapping ("/login ") public String Login (user user,httpservletrequest request) {User resultuser=userservice.login (user); if (resultuser==null) { Request.setattribute ("user", user), Request.setattribute ("ErrorMsg", "Username or password error!") "); return" index ";} Else{httpsession session=request.getsession (); Session.setattribute ("CurrentUser", Resultuser); return "redirect:/ Success.jsp ";}}}
1.3 Writing SPRING-MVC configuration file/user-web/src/main/resources/spring-mvc.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:p= "http://www.springframework.org/schema/p" xmlns:aop= "H Ttp://www.springframework.org/schema/aop "xmlns:context=" Http://www.springframework.org/schema/context "xmlns:j Ee= "Http://www.springframework.org/schema/jee" xmlns:tx= "Http://www.springframework.org/schema/tx" Xsi:schemaloc          ation= "Http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd          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/jee Http://www.springframework.org/schema/jee/sprin G-jee-4.0.xsd Http://www.springframework.Org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd "> <!--packages that use annotations, including subsets-->< Context:component-scan base-package= "Cn.anstone.controller"/><!--View parser--><bean id= "Viewresolver" class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" ><property name= "prefix" value= "/   "/><property name=" suffix "value=". JSP ></property></bean></beans>

1.4 Writing the Web. XML configuration File/user-web/src/main/webapp/web-inf/web.xml
<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://java.sun.com/xml/ns/javaee" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee/http Java.sun.com/xml/ns/javaee/web-app_3_0.xsd "id=" webapp_id "version=" 3.0 "> <display-name>MyBatisPro05< /display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </ Welcome-file-list> <!--spring configuration file--><context-param><param-name>contextconfiglocation</p aram-name><param-value>classpath:applicationcontext.xml</param-value></context-param>< !--coded Filter--><filter><filter-name>encodingfilter</filter-name><filter-class> org.springframework.web.filter.characterencodingfilter</filter-class><async-supported>true</ async-supported><init-param><param-name>encoding</param-name><param-value>utf-8< /param-value></init-param></filter><filter-mapping><filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern></filter-mapping><!--Spring Listener--><listener>< Listener-class>org.springframework.web.context.contextloaderlistener</listener-class></listener ><!--Add support for SPRINGMVC--><servlet><servlet-name>springmvc</servlet-name>< servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class><init-param>< param-name>contextconfiglocation</param-name><param-value>classpath:spring-mvc.xml</ Param-value></init-param><load-on-startup>1</load-on-startup><async-supported>true </async-supported></servlet><servlet-mapping><servlet-name>springmvc</servlet-name ><url-pattern>*.do</url-pattern></servlet-mapping> </web-app>

1.5 Writing JSP pages/user-web/src/main/webapp/index.jsp
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >

/user-web/src/main/webapp/success.jsp
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "    pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >

Eclipse use maven S3

Related Article

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.