JAVAWEB 一一SpringMVC(XML配置)
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></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*do</url-pattern>
</servlet-mapping>
</web-app>
springmvc-servlet.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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.2.xsd"> <!-- 简单url地址处理器映射 -->
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" >
<property name="mappings">
<props>
<prop key="/login.do">userController</prop>
</props>
</property>
</bean>
<bean name ="userController" class="com.springmvc.controller.UserController">
<property name="userService" ref="userService"></property>
</bean>
<bean id="userService" class="com.springmvc.service.UserServiceImpl"/>
<!-- 视图解析器-->
<!-- /WEB-INF/jsp/success.jsp -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
controller
package com.springmvc.controller; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller; import com.springmvc.service.UserService; public class UserController implements Controller { private UserService userService;
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
String username = request.getParameter("username");
String password = request.getParameter("password");
boolean islogin = userService.login(username, password); /*
* 可以自己建对象 传数据到页面
* List<Object>list = new ArrayList<Object>();
list.add(1);
list.add(1);
list.add(1);
list.add(1); ModelAndView mv = new ModelAndView();
mv.setViewName("success"); list.add("t");
list.add("te");
list.add("tes");
list.add("test");
mv.addObject("list",list);*/ if(islogin){
return new ModelAndView("success");
//return mv;
}else{
return new ModelAndView("login");
}
}
public UserService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
this.userService = userService;
} }
JAVAWEB 一一SpringMVC(XML配置)的更多相关文章
- SpringMVC、SpringMVC XML配置(纯XML方式)
1.引入SrpingMVC所使用的Java包: cglib-nodep-2.1_3.jar.commons-logging.jar.spring-aspects-4.1.7.RELEASE.jar.s ...
- springmvc访问静态资源的springmvc.xml配置
一. 问题及需求 由于Spring MVC的web.xml文件中关于DispatcherServlet拦截url的配置为"/",拦截了所有的请求,同时*.js,*.jpg等静态资源 ...
- SpringMvc xml 配置
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" ...
- spring-mvc.xml配置
1.自动扫描 <!-- 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器 --> <context:component-scan base-pac ...
- springmvc.xml配置
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- SpringMvc多视图配置(jsp、velocity、freemarker) velocity在springmvc.xml配置VelocityViewResolver,VelocityConfigurer,FreeMarkerConfigurer,FreeMarkerViewResolver
?xml version="1.0"encoding="UTF-8"?> <beans xmlns="http://www.springf ...
- JAVAWEB 一一 SpringMVC(注解)
web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="2 ...
- springmvc.xml配置图解
- springmvc.xml和applicationContext.xml配置的特点
1:springmvc.xml配置要点 一般它主要配置Controller的组件扫描器和视图解析器 下为:springmvc.xml文件 <?xml version="1.0" ...
随机推荐
- MapReduce Demo
功能:统计公司员工一个月内手机上网上行流量.下行流量及总流量. 测试数据如下: 13612345678 6000 1000 13612345678 2000 3000 13 ...
- 点不到的NO
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...
- 提示:pip install --upgrade pip
安装模块时报错了,提示我需要更新pip,如下所示: 但是使用pip install --upgrade pip时依然报这个错,原来是命令应该这样写: python -m pip install -U ...
- 利用Python实现FGO自动战斗脚本,再也不用爆肝啦~
Fate/Grand Order(非的肝不过欧的)作为索尼为了拯救自己不倒闭而开发的面向月厨的骗氪养成抽卡爆肝游戏,居然没有像隔壁<阴阳师>的自动战斗系统(看看别人现在都自带脚本了).毕竟 ...
- GNU C语言开发环境
1. GNU C 编译器 2. GNU make 项目管理工具 3. 创建和使用函数库 4. GNU C 函数库(glibc) 1.GNU C 编译器 使用 c语言 编写的代码,运行前必须经过编译和链 ...
- Vue.js模拟百度下拉框
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- javafx链接实现
方式一: Desktop.getDesktop().browse(new URI(manualUrl)); 在linux环境bug 方式二: 转载自:https://stackoverflow.com ...
- 学习笔记:webpack
http://wiki.jikexueyuan.com/project/webpack-handbook/ Webpack 中文指南 http://www.itzjt.cc/2017/04/09/we ...
- JavaScript:今天是今年第几周?
用js实现,今天是今年第几周? 基本思路: 1.当前时间 - 今年1月1日0时,拿到时间差(毫秒数) 2.时间差/7天毫秒数,向上取整 var d = new Date('2018-01-01 00: ...
- 解决git中文乱码问题
三条命令fix乱码问题: git config --global gui.encoding utf-8 git config --global i18n.commitencoding utf-8 gi ...