SpringMVC 实现登录注册 ゝ一纸荒年。 2021-09-22 10:18 538阅读 0赞 基本配置步骤: 1、新增spring-mvc配置文件 2、新增log4j配置文件 3、在Java Resorces下创建resources文件夹,把1、2中的文件放到这个文件夹 4、在WEB-INF目录下创建classes目录 5、修改项目编译输出路径到classes目录 6、把jar包添加到编译路径 7、把jar包添加到Deploy and Assemblyment [==> jar包下载][jar] 项目结构: ![SouthEast][] web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name>springmvc</display-name> <!-- 配置DispatchcerServlet --> <servlet> <servlet-name>spring-mvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- Spring mvc配置文件的位置和名称 --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring-mvc</servlet-name> <url-pattern>/</url-pattern> <!-- 所有的的请求,都会被DispatcherServlet处理 --> </servlet-mapping> <filter> <filter-name>EncodingFilter</filter-name> <!--编码过滤器--> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <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> </web-app> 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:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> <!-- 配置自动扫描的包 --> <context:component-scan base-package="com.cheese.controller"></context:component-scan> <mvc:annotation-driven /> <!-- 配置视图解析器 把handler 方法返回值解析为实际的物理视图 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name = "prefix" value="/WEB-INF/views/"></property> <property name = "suffix" value = ".jsp"></property> </bean> </beans> log4j.properties ### direct log messages to stdout ### log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n ### direct messages to file springmvc.log ### log4j.appender.file=org.apache.log4j.FileAppender log4j.appender.file.File=${catalina.base}/logs/springmvc.log log4j.appender.file.layout=org.apache.log4j.PatternLayout #log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n ### set log levels - for more verbose logging change 'info' to 'debug' ### log4j.rootLogger=debug,stdout,file spring jar包 ![SouthEast 1][] 项目编译设置: ![SouthEast 2][] ![SouthEast 3][] ![SouthEast 4][] index.jsp ![SouthEast 5][] regUser.jsp ![SouthEast 6][] login.jsp ![SouthEast 7][] welcome.jsp ![SouthEast 8][] User.java ![SouthEast 9][] UserController.java ![SouthEast 10][]![SouthEast 11][] ![SouthEast 12][] 运行测试 ![SouthEast 13][] ![SouthEast 14][] ![SouthEast 15][] ![SouthEast 16][] [jar]: https://download.csdn.net/download/write6/10332383 [SouthEast]: /images/20210920/83803bc367dd4f4b95116844faf5319e.png [SouthEast 1]: /images/20210920/a6db80edd65345e6ac9ba3afefe24d0c.png [SouthEast 2]: /images/20210920/d5b44877a03548de9a8ca95494b4c578.png [SouthEast 3]: /images/20210920/f14732566c614fe18d871f42dbbf5030.png [SouthEast 4]: /images/20210920/e81f55d53d6145b3a2e1832b807cb148.png [SouthEast 5]: /images/20210920/d0090a42c4f14f769b3ee4b9ac1aaef4.png [SouthEast 6]: /images/20210920/8a1c15b4e92a4cd5a79472a1236a82c2.png [SouthEast 7]: /images/20210920/dd0df2a404c74248b1b0e3fefecc23bf.png [SouthEast 8]: /images/20210920/62d36bac15a34862be83cf9e6bf7b22a.png [SouthEast 9]: /images/20210920/e4837f2cd9794fa4833bceba5cb6518f.png [SouthEast 10]: https://img-blog.csdn.net/20180124210645564?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvd3JpdGU2/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast [SouthEast 11]: /images/20210920/8e8e468d623a46f397d44b169fc9ea81.png [SouthEast 12]: /images/20210920/e6ca6f4d517f4e7a950b26669fb44a01.png [SouthEast 13]: /images/20210920/54b8e9cb8c48475a9d19001cfe34426f.png [SouthEast 14]: /images/20210920/a531e81e50d74677a8e5920a2b81a7af.png [SouthEast 15]: /images/20210920/c2d544e9dd37408894c0d7cd19876e2d.png [SouthEast 16]: /images/20210920/17d4e8da87134326bcb1c47cac77b567.png
还没有评论,来说两句吧...