Spring+SpringMVC+Mybatis+Maven+CXF+WebService整合之服务端
Posted on 2018-07-26 13:54 安然格思 阅读(2318) 评论(0) 编辑 收藏 举报WebService服务端项目结构:
![](https://images2018.cnblogs.com/blog/1157064/201807/1157064-20180726135731491-1422617657.png)
![](https://images2018.cnblogs.com/blog/1157064/201807/1157064-20180726135909558-918790185.png)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <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/xsd/maven-4.0.0.xsd"> 2 <modelVersion>4.0.0</modelVersion> 3 <groupId>com.erry</groupId> 4 <artifactId>HydSSMDemo2</artifactId> 5 <version>0.0.1-SNAPSHOT</version> 6 <packaging>war</packaging> 7 8 <properties> 9 <!-- spring版本号 --> 10 <spring.version>4.0.2.RELEASE</spring.version> 11 <!-- mybatis版本号 --> 12 <mybatis.version>3.2.6</mybatis.version> 13 <!-- log4j日志文件管理包版本 --> 14 <!-- <slf4j.version>1.7.7</slf4j.version> --> 15 <!-- <log4j.version>1.2.17</log4j.version> --> 16 </properties> 17 18 <dependencies> 19 <dependency> 20 <groupId>junit</groupId> 21 <artifactId>junit</artifactId> 22 <version>3.8.1</version> 23 <!-- 表示开发的时候引入,发布的时候不会加载此包 --> 24 <scope>test</scope> 25 </dependency> 26 <!-- <dependency> 27 <groupId>javax.servlet</groupId> 28 <artifactId>javax.servlet-api</artifactId> 29 <version>3.1.0</version> 30 </dependency> --> 31 32 <!-- spring核心包 --> 33 <dependency> 34 <groupId>org.springframework</groupId> 35 <artifactId>spring-core</artifactId> 36 <version>${spring.version}</version> 37 </dependency> 38 39 <dependency> 40 <groupId>org.springframework</groupId> 41 <artifactId>spring-web</artifactId> 42 <version>${spring.version}</version> 43 </dependency> 44 <dependency> 45 <groupId>org.springframework</groupId> 46 <artifactId>spring-oxm</artifactId> 47 <version>${spring.version}</version> 48 </dependency> 49 <dependency> 50 <groupId>org.springframework</groupId> 51 <artifactId>spring-tx</artifactId> 52 <version>${spring.version}</version> 53 </dependency> 54 55 <dependency> 56 <groupId>org.springframework</groupId> 57 <artifactId>spring-jdbc</artifactId> 58 <version>${spring.version}</version> 59 </dependency> 60 61 <dependency> 62 <groupId>org.springframework</groupId> 63 <artifactId>spring-webmvc</artifactId> 64 <version>${spring.version}</version> 65 </dependency> 66 <dependency> 67 <groupId>org.springframework</groupId> 68 <artifactId>spring-aop</artifactId> 69 <version>${spring.version}</version> 70 </dependency> 71 72 <dependency> 73 <groupId>org.springframework</groupId> 74 <artifactId>spring-context-support</artifactId> 75 <version>${spring.version}</version> 76 </dependency> 77 78 <dependency> 79 <groupId>org.springframework</groupId> 80 <artifactId>spring-test</artifactId> 81 <version>${spring.version}</version> 82 </dependency> 83 <!-- mybatis核心包 --> 84 <dependency> 85 <groupId>org.mybatis</groupId> 86 <artifactId>mybatis</artifactId> 87 <version>${mybatis.version}</version> 88 </dependency> 89 <!-- mybatis/spring包 --> 90 <dependency> 91 <groupId>org.mybatis</groupId> 92 <artifactId>mybatis-spring</artifactId> 93 <version>1.2.2</version> 94 </dependency> 95 96 <!-- 导入java ee jar 包 --> 97 <dependency> 98 <groupId>javax</groupId> 99 <artifactId>javaee-api</artifactId> 100 <version>7.0</version> 101 </dependency> 102 103 <!-- 导入dbcp的jar包,用来在applicationContext.xml中配置数据库 --> 104 <dependency> 105 <groupId>commons-dbcp</groupId> 106 <artifactId>commons-dbcp</artifactId> 107 <version>1.2.2</version> 108 </dependency> 109 110 <!-- JSTL标签类 --> 111 <dependency> 112 <groupId>jstl</groupId> 113 <artifactId>jstl</artifactId> 114 <version>1.2</version> 115 </dependency> 116 <!-- 日志文件管理包 --> 117 <!-- log start --> 118 <!-- <dependency> --> 119 <!-- <groupId>log4j</groupId> --> 120 <!-- <artifactId>log4j</artifactId> --> 121 <!-- <version>${log4j.version}</version> --> 122 <!-- </dependency> --> 123 124 125 <!-- 格式化对象,方便输出日志 --> 126 <!-- <dependency> --> 127 <!-- <groupId>com.alibaba</groupId> --> 128 <!-- <artifactId>fastjson</artifactId> --> 129 <!-- <version>1.1.41</version> --> 130 <!-- </dependency> --> 131 132 133 <!-- <dependency> --> 134 <!-- <groupId>org.slf4j</groupId> --> 135 <!-- <artifactId>slf4j-api</artifactId> --> 136 <!-- <version>${slf4j.version}</version> --> 137 <!-- </dependency> --> 138 <!-- --> 139 <!-- <dependency> --> 140 <!-- <groupId>org.slf4j</groupId> --> 141 <!-- <artifactId>slf4j-log4j12</artifactId> --> 142 <!-- <version>${slf4j.version}</version> --> 143 <!-- </dependency> --> 144 <!-- log end --> 145 <!-- 映入JSON --> 146 <dependency> 147 <groupId>org.codehaus.jackson</groupId> 148 <artifactId>jackson-mapper-asl</artifactId> 149 <version>1.9.13</version> 150 </dependency> 151 <!-- 上传组件包 --> 152 <!-- <dependency> --> 153 <!-- <groupId>commons-fileupload</groupId> --> 154 <!-- <artifactId>commons-fileupload</artifactId> --> 155 <!-- <version>1.3.1</version> --> 156 <!-- </dependency> --> 157 <!-- <dependency> --> 158 <!-- <groupId>commons-io</groupId> --> 159 <!-- <artifactId>commons-io</artifactId> --> 160 <!-- <version>2.4</version> --> 161 <!-- </dependency> --> 162 <!-- <dependency> --> 163 <!-- <groupId>commons-codec</groupId> --> 164 <!-- <artifactId>commons-codec</artifactId> --> 165 <!-- <version>1.9</version> --> 166 <!-- </dependency> --> 167 168 <dependency> 169 <groupId>org.apache.cxf</groupId> 170 <artifactId>cxf-rt-transports-http</artifactId> 171 <version>3.1.8</version> 172 </dependency> 173 <!--web service 以下都是cxf必备的--> 174 <dependency> 175 <groupId>org.apache.cxf</groupId> 176 <artifactId>cxf-rt-transports-http</artifactId> 177 <version>3.1.8</version> 178 </dependency> 179 <!-- 180 不加这个包会报错Unable to locate spring NamespaceHandler for XML schema 181 namespace [http://cxf.apache.org/jaxws] 182 --> 183 <dependency> 184 <groupId>org.apache.cxf</groupId> 185 <artifactId>cxf-rt-frontend-jaxws</artifactId> 186 <version>3.1.8</version> 187 </dependency> <!--java实现webservice,不部署到tomcat,需要jetty包支持--> 188 <dependency> 189 <groupId>org.apache.cxf</groupId> 190 <artifactId>cxf-rt-transports-http-jetty</artifactId> 191 <version>3.1.8</version> 192 </dependency> 193 194 </dependencies> 195 196 </project>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 package com.javen.model; 2 3 import java.io.Serializable; 4 5 public class User implements Serializable{ 6 private Integer id; 7 8 private String userName; 9 10 private String password; 11 12 private Integer age; 13 14 public Integer getId() { 15 return id; 16 } 17 18 public void setId(Integer id) { 19 this.id = id; 20 } 21 22 public String getUserName() { 23 return userName; 24 } 25 26 public void setUserName(String userName) { 27 this.userName = userName == null ? null : userName.trim(); 28 } 29 30 public String getPassword() { 31 return password; 32 } 33 34 public void setPassword(String password) { 35 this.password = password == null ? null : password.trim(); 36 } 37 38 public Integer getAge() { 39 return age; 40 } 41 42 public void setAge(Integer age) { 43 this.age = age; 44 } 45 46 @Override 47 public String toString() { 48 return "User [id=" + id + ", userName=" + userName + ", password=" 49 + password + ", age=" + age + "]"; 50 } 51 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 package com.javen.dao; 2 3 import java.util.ArrayList; 4 import java.util.Map; 5 6 import com.javen.model.User; 7 8 public interface UserMapper{ 9 10 public ArrayList<User> selectAll(); 11 12 public Integer selectLogin(Map map); 13 14 public User selectById(int id); 15 16 public void updateById(int id); 17 18 public void deleteById(int id); 19 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 3 <mapper namespace="com.javen.dao.UserMapper"> 4 <resultMap id="BaseResultMap" type="com.javen.model.User"> 5 <id column="id" jdbcType="BIGINT" property="id" /> 6 <!-- column 代表数据库一方,property代表实体类一方 --> 7 <result column="user_name" jdbcType="VARCHAR" property="userName" /> 8 <result column="password" jdbcType="VARCHAR" property="password" /> 9 <result column="age" jdbcType="BIGINT" property="age"/> 10 </resultMap> 11 <!-- resultMap返回复数的结果 --> 12 <select id="selectAll" resultMap="BaseResultMap"> 13 select * from user_t 14 </select> 15 <!-- 参数类型为Map,可以有多个值,返回值类型为Integer --> 16 <select id="selectLogin" parameterType="Map" resultType="Integer"> 17 select id from user_t where user_name=#{userName} and password=#{password} 18 </select> 19 20 </mapper>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 package com.javen.service; 2 import java.util.ArrayList; 3 import java.util.Map; 4 import javax.jws.WebMethod; 5 import javax.jws.WebService; 6 import com.javen.model.User; 7 //表示这是一个@WebService服务接口 8 @WebService 9 public interface IUserService { 10 //@WebMethod注解,表示服务发布时被注解的方法也会随之发布 11 @WebMethod 12 public ArrayList<User> selectAll(); 13 @WebMethod 14 public Integer selectLogin(Map map); 15 @WebMethod 16 public User selectById(int id); 17 @WebMethod 18 public void updateById(int id); 19 @WebMethod 20 public void deleteById(int id); 21 22 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 package com.javen.service.impl; 2 3 import java.util.ArrayList; 4 import java.util.Map; 5 6 import javax.jws.WebService; 7 8 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.stereotype.Service; 10 11 import com.javen.dao.UserMapper; 12 import com.javen.model.User; 13 import com.javen.service.IUserService; 14 //这是接口的实现类。 endpointInterface属性,格式:包名.接口名 15 @Service 16 @WebService(endpointInterface="com.javen.service.IUserService") 17 public class UserServiceImpl implements IUserService{ 18 19 @Autowired 20 UserMapper userDao; 21 // @Autowired 22 User user; 23 24 25 public void deleteById(int id) { 26 // TODO Auto-generated method stub 27 28 } 29 30 public ArrayList<User> selectAll() { 31 ArrayList<User> user=userDao.selectAll(); 32 return user; 33 34 } 35 36 public Integer selectLogin(Map map) { 37 return userDao.selectLogin(map); 38 } 39 40 public User selectById(int id) { 41 // TODO Auto-generated method stub 42 return null; 43 } 44 45 public void updateById(int id) { 46 // TODO Auto-generated method stub 47 48 } 49 50 51 52 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 package com.javen.controller; 2 3 import java.util.ArrayList; 4 import java.util.HashMap; 5 import java.util.Map; 6 7 import javax.servlet.http.HttpServletRequest; 8 9 //import org.slf4j.Logger; 10 //import org.slf4j.LoggerFactory; 11 import org.springframework.beans.factory.annotation.Autowired; 12 import org.springframework.http.HttpRequest; 13 import org.springframework.stereotype.Controller; 14 import org.springframework.ui.Model; 15 import org.springframework.web.bind.annotation.PathVariable; 16 import org.springframework.web.bind.annotation.RequestMapping; 17 import org.springframework.web.bind.annotation.RequestMethod; 18 import org.springframework.web.bind.annotation.ResponseBody; 19 20 import com.javen.model.User; 21 import com.javen.service.IUserService; 22 23 24 @Controller 25 @RequestMapping("/") 26 public class UserController { 27 @Autowired 28 IUserService iUserService; 29 30 @RequestMapping("/") 31 public String login(){ 32 return "login"; 33 } 34 35 @RequestMapping(value="loginUser",method={RequestMethod.POST}) 36 @ResponseBody 37 public int loginUser(HttpServletRequest request,Model model){ 38 System.out.println("login..."); 39 Map map=new HashMap(); 40 String userName=request.getParameter("userName"); 41 String password=request.getParameter("password"); 42 System.out.println("账号:"+userName+"\n"+"密码:"+password); 43 map.put("userName", userName); 44 map.put("password", password); 45 Integer id=iUserService.selectLogin(map); 46 System.out.println("id:"+id); 47 return id; 48 49 } 50 51 @RequestMapping("/test") 52 public String test(HttpServletRequest request,Model model){ 53 System.out.println("test"); 54 ArrayList<User> user=iUserService.selectAll(); 55 model.addAttribute("user", user); 56 return "index"; 57 } 58 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 package com.javen.listener; 2 //import java.net.MalformedURLException; 3 //import javax.xml.ws.Endpoint; 4 //import com.javen.service.impl.UserServiceImpl; 5 6 public class WebServicePublishListener{ 7 //WebService服务发布 8 // public static void main(String[] args) 9 // throws MalformedURLException { 10 // Endpoint.publish("http://localhost:11111/WS_WebService", new UserServiceImpl()); 11 // 12 // } 13 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 driver=com.microsoft.sqlserver.jdbc.SQLServerDriver 2 url=jdbc:sqlserver://localhost:1433;databaseName=HydSSmDemo_TEST 3 username=ZOOUSER 4 password=ZOOUSER
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" 4 xmlns:context="http://www.springframework.org/schema/context" 5 xmlns:mvc="http://www.springframework.org/schema/mvc" 6 xsi:schemaLocation="http://www.springframework.org/schema/beans 7 http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 8 http://www.springframework.org/schema/context 9 http://www.springframework.org/schema/context/spring-context-3.1.xsd 10 http://www.springframework.org/schema/mvc 11 http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> 12 <!-- 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器 --> 13 <context:component-scan base-package="com.javen.controller" /> 14 <!-- 扩充了注解驱动,可以将请求参数绑定到控制器参数 --> 15 <mvc:annotation-driven/> 16 <!-- 静态资源处理 css js imgs --> 17 <mvc:resources location="/css/" mapping="/css/**"></mvc:resources> 18 <mvc:resources location="/js/" mapping="/js/**"></mvc:resources> 19 <!-- 启动SpringMVC的注解功能 --> 20 <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/> 21 <!-- 定义跳转的文件的前后缀 ,视图模式配置--> 22 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 23 <!-- 这里的配置我的理解是自动给后面action的方法return的字符串加上前缀和后缀,变成一个 可用的url地址 --> 24 <property name="prefix" value="/WEB-INF/jsp/" /> 25 <property name="suffix" value=".jsp" /> 26 </bean> 27 </beans>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" 4 xmlns:context="http://www.springframework.org/schema/context" 5 xmlns:mvc="http://www.springframework.org/schema/mvc" 6 xsi:schemaLocation="http://www.springframework.org/schema/beans 7 http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 8 http://www.springframework.org/schema/context 9 http://www.springframework.org/schema/context/spring-context-3.1.xsd 10 http://www.springframework.org/schema/mvc 11 http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> 12 <!-- 自动扫描 --> 13 <context:component-scan base-package="com.javen" /> 14 15 <!-- 引入配置文件 --> 16 <bean id="propertyConfigurer" 17 class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 18 <property name="location" value="classpath:jdbc.properties" /> 19 </bean> 20 21 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 22 destroy-method="close"> 23 <property name="driverClassName" value="${driver}" /> 24 <property name="url" value="${url}" /> 25 <property name="username" value="${username}" /> 26 <property name="password" value="${password}" /> 27 <!-- 初始化连接大小 --> 28 <property name="initialSize" value="${initialSize}"></property> 29 <!-- 连接池最大数量 --> 30 <property name="maxActive" value="${maxActive}"></property> 31 <!-- 连接池最大空闲 --> 32 <property name="maxIdle" value="${maxIdle}"></property> 33 <!-- 连接池最小空闲 --> 34 <property name="minIdle" value="${minIdle}"></property> 35 <!-- 获取连接最大等待时间 --> 36 <property name="maxWait" value="${maxWait}"></property> 37 </bean> 38 39 <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 --> 40 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> 41 <property name="dataSource" ref="dataSource" /> 42 <!-- 自动扫描mapper.xml文件 --> 43 <property name="mapperLocations" value="classpath:com/javen/dao/*.xml"></property> 44 </bean> 45 46 <!-- DAO接口所在包名,Spring会自动查找其下的类 --> 47 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> 48 <property name="basePackage" value="com.javen.dao" /> 49 <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> 50 </bean> 51 52 <!-- (事务管理)transaction manager, use JtaTransactionManager for global tx --> 53 <bean id="transactionManager" 54 class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 55 <property name="dataSource" ref="dataSource" /> 56 </bean> 57 58 </beans>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:jaxws="http://cxf.apache.org/jaxws" 5 xsi:schemaLocation="http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd 6 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" 7 default-lazy-init="true"> 8 <!-- 引入CXF Bean定义如下,早期的版本中使用 。 --> 9 <!-- 3.0以下都需要引入这三个文件,3.0以上只需要cxf.xml这一个xml文件就好 --> 10 <!-- <import resource="classpath*:META-INF/cxf/cxf.xml" /> --> 11 <!-- <import resource="classpath*:META-INF/cxf/cxf-extension-soap.xml" /> --> 12 <!-- <import resource="classpath*:META-INF/cxf/cxf-servlet.xml" />--> 13 14 <!--xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 发布webservice xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx--> 15 <!-- WebService的实现Bean定义 --> 16 <!-- com.javen.service.impl.UserServiceImpl是接口实现类 17 web.xml配置了webservice的访问路径/server/*,那么/server/web-publish?wsdl就是该webservice的访问路径; 18 该webservice的访问路径前面要加上项目的路径 localhost:8080/项目名/server/web-publish?wsdl 19 --> 20 <bean id="iUserService" class="com.javen.service.impl.UserServiceImpl" /> 21 <!-- 1.jax-ws endpoint定义 22 2.implementor="#iUserService",iUserService是接口,首字母小写 23 3. jaxws:endpoint标签的id自定义就好 24 4.address="/web-publish"是服务发布的地址,和web.xml中的<url-pattern>/server/*</url-pattern>标签的值相结合--> 25 <jaxws:endpoint id="myService" implementor="#iUserService" 26 address="/web-publish"> 27 </jaxws:endpoint> 28 <!--xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 发布webservice xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx--> 29 </beans>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> 3 <display-name>HydSSmDemo</display-name> 4 <welcome-file-list> 5 <welcome-file>index.html</welcome-file> 6 <welcome-file>index.htm</welcome-file> 7 <welcome-file>index.jsp</welcome-file> 8 <welcome-file>default.html</welcome-file> 9 <welcome-file>default.htm</welcome-file> 10 <welcome-file>default.jsp</welcome-file> 11 </welcome-file-list> 12 13 14 <!-- Spring和mybatis和webservice的配置文件 --> 15 <context-param> 16 <param-name>contextConfigLocation</param-name> 17 <param-value>classpath:spring*.xml</param-value> 18 </context-param> 19 <!-- 编码过滤器 --> 20 <filter> 21 <filter-name>encodingFilter</filter-name> 22 <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 23 <async-supported>true</async-supported> 24 <init-param> 25 <param-name>encoding</param-name> 26 <param-value>UTF-8</param-value> 27 </init-param> 28 </filter> 29 <filter-mapping> 30 <filter-name>encodingFilter</filter-name> 31 <url-pattern>/*</url-pattern> 32 </filter-mapping> 33 <!-- Spring监听器 --> 34 <listener> 35 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 36 </listener> 37 <!-- 防止Spring内存溢出监听器 --> 38 <listener> 39 <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class> 40 </listener> 41 42 <!-- Spring MVC servlet --> 43 <servlet> 44 <servlet-name>SpringMVC</servlet-name> 45 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 46 <init-param> 47 <param-name>contextConfigLocation</param-name> 48 <param-value>classpath:spring-mvc.xml</param-value> 49 </init-param> 50 </servlet> 51 <servlet-mapping> 52 <servlet-name>SpringMVC</servlet-name> 53 <!-- 此处可以可以配置成*.do,对应struts的后缀习惯 --> 54 <url-pattern>/</url-pattern> 55 </servlet-mapping> 56 57 <!-- ??CXF?????Servlet --> 58 <servlet> 59 <servlet-name>CXFServlet</servlet-name> 60 <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> 61 <load-on-startup>2</load-on-startup> 62 </servlet> 63 <!--<url-pattern>/server/*</url-pattern> 服务发布的url,和address="/web-publish"还有项目路径相互组合成完整的服务发布链接 64 http://localhost:8080/WS_WebService/server/web-publish?wsdl --> 65 <servlet-mapping> 66 <servlet-name>CXFServlet</servlet-name> 67 <url-pattern>/server/*</url-pattern> 68 </servlet-mapping> 69 70 </web-app>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 $(function(){ 2 $("#sub").click(function(){ 3 var userName=$("#userName").val(); 4 var password=$("#password").val(); 5 $.ajax({ 6 type:'post', 7 dataType:'json', 8 url:'./loginUser', 9 async: true, 10 data:{ 11 userName:$("#userName").val(), 12 password:$("#password").val() 13 }, 14 success:function(data){ 15 if(data!=null){ 16 alert("success"); 17 window.location.href='./test'; 18 } 19 } 20 }); 21 }); 22 23 24 $("#res").click(function(){ 25 $("#userName").val(""); 26 $("#password").val(""); 27 }); 28 29 });
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 table tr td{ 2 text-align:center; 3 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 4 5 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 6 <html> 7 <head> 8 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 9 <title>Insert title here</title> 10 <link href="${pageContext.request.contextPath}/css/table_Style.css" rel="stylesheet" type="text/css"> 11 <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.3.1.min.js"></script> 12 <script type="text/javascript" src="${pageContext.request.contextPath}/js/table_Style.js"></script> 13 </head> 14 <body> 15 <h1 style='color:red'>Hello word!</h1> 16 <body> 17 <table id="" cellpadding="0" cellspacing="0" border="1" width="700"> 18 <tr> 19 <th>序号</th><th>姓名</th><th>年龄</th> 20 </tr> 21 <c:forEach items="${user}" var="u" varStatus="stat"> 22 <tr> 23 <td>${stat.index+1}</td><td>${u.userName}</td><td>${u.age}</td> 24 </tr> 25 </c:forEach> 26 </table> 27 </body> 28 </html>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 7 <title>Insert title here</title> 8 <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.3.1.min.js"></script> 9 <script type="text/javascript" src="${pageContext.request.contextPath}/js/table_Style.js"></script> 10 </head> 11 <body> 12 <h1>Login</h1> 13 <table id="" cellpadding="0" cellspacing="0" border="1" width="300"> 14 <tr> 15 <td align="right">登录名:</td><td> 16 <input type="text" id="userName" name="userName"> 17 </td> 18 </tr> 19 <tr> 20 <td align="right">密码:</td><td> 21 <input type="password" id="password" name="password"> 22 </td> 23 </tr> 24 <tr> 25 <td align="center" colspan="2"> 26 <input type="button" id="sub" value="登录"> 27 <input type="reset" id="res" value="清空"> 28 </td> 29 </tr> 30 </table> 31 32 33 </body> 34 </html>
项目启动成功后进入 http://localhost:8080/WS_WebService/server/web-publish?wsdl 页面查看 WSDL(WebService描述语言)
项目登录页面链接: http://localhost:8080/WS_WebService/