springmvc----demo---login---bai

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">
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:component-scan base-package="com.etc.controller">
</context:component-scan> <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver" >
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
</bean>
</beans> ========================================================================== login.jsp: <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
${msg }
<form action="login.html" method="post">
用户名: <input name="username" /> <br/>
密码: <input name="password" type="password"/><br/>
<input type="submit" value="登录"/>
</form>
</body>
</html>
========================================================================== LoginAction: package com.etc.controller; import java.util.HashMap;
import java.util.Map; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView; @Controller
public class LoginAction
{
@RequestMapping(value="/login",method=RequestMethod.POST)
public ModelAndView login(@RequestParam(value="username",required=true)String username
,@RequestParam(value="password",required=true)String password)
{
Map<String,String> model = new HashMap<String,String>();
ModelAndView ma = null;
//判断是否正确
if("admin".equals(username)&&"123".equals(password))
{
model.put("username", username);
ma = new ModelAndView("welcome", model);
}
else
{
model.put("msg", "用户名或密码错误!");
ma = new ModelAndView("../../login", model);
}
return ma;
}
}
==========================================================================
welcome.jsp: <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'welcome.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head> <body>
登录成功,欢迎${username }。
</body>
</html>
==========================================================================
springmvc----demo---login---bai的更多相关文章
- 【Spring学习】SpringMVC demo搭建
前言:今天会通过IDEA建立一个SpringMVC的demo项目,在其中会涉及到一些基础模块和相关知识,然后结合这个具体的知识点,理解清楚SpringMVC的框架原理(以图的形式展示),顺藤摸瓜分析源 ...
- springMVC demo搭建
1.使用idea新建一个基于maven的web项目,参考 http://www.cnblogs.com/winkey4986/p/5279820.html 2.采取了比较偷懒的配置方法,只配置了一个D ...
- springmvc demo
[说明]今天上午稍稍偏了一下方向,看了看servlet的相关知识,下午做maven+spring+springMVC的整合,晚上成功实现了一个小demo(可以在jsp动态页面上获得通过地址栏输入的参数 ...
- SpringMVC demo 小例子,实现简单的登录和注册
1.创建一个动态的web工程 2.导入springMvc所需要的jar包(这里可以去网上找,资源有很多) 前两部就不详细描述了,后面才是正经代码~ 首先有一个web.xml文件,这个属于大配置文件,由 ...
- SpringMvc demo示例及源码详细分析
三层架构介绍 我们的开发架构一般都是基于两种形式,一种C/S架构,也就是客户端/服务器,另一种是B/S架构,也就是浏览器/服务器.在JavaEE开发中,几乎全部都是基于B/S架构的开发.那么在B/S架 ...
- IntelliJ IDEA springmvc demo
construction pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=" ...
- 【SSH系列】深入浅出SpringMvc+入门Demo
Spring MVC框架是有一个MVC框架,通过实现Model-View-Controller模式来很好地将数据.业务与展现进行分离.从这样一个角度来说,Spring MVC和Struts.Strut ...
- 在Eclipse中使用Maven构建SpringMVC项目
环境搭建 安装JDK, Eclipse, Tomcat等 – 请参考网上常见攻略. 安装Maven: 下载需要的Maven 版本( http://maven.apache.org/download.c ...
- JAVA WEB快速入门之从编写一个基于SpringMVC框架的网站了解Maven、SpringMVC、SpringJDBC
接上篇<JAVA WEB快速入门之通过一个简单的Spring项目了解Spring的核心(AOP.IOC)>,了解了Spring的核心(AOP.IOC)后,我们再来学习与实践Maven.Sp ...
- 【Spring】SpringMVCの環境構築(簡)(Version3.1)
■Mavenでプロジェクトの新規 ■プロジェクトのイメージ ■必要なラブリア ■ソース ①pom.xml <?xml version="1.0" encoding=" ...
随机推荐
- EF Code-First 学习之旅 继承策略
Code First中有三种不同的方法表示继承层次关系 1.Table per Hierarchy (TPH): 这种方法建议用一个表来表示整个类的继承层次关系,表中包含一个识别列来区分继承类,在En ...
- mysql基础(3)-高级查询
聚合函数 count 返回查询结果的条数 max 返回查询结果的最大值 min 返回查询结果的最小值 sum 返回查询结果的和 avg 返回查询结果的平均值 统计分数大于等于90的人数: mysq ...
- javascript(jquery)_匿名函数
一.什么是匿名函数 匿名函数:就是没有函数名的函数 二.为什么使用匿名函数 1.最大的用处就是创建闭包 三.匿名函数定义(怎么使用匿名函数) 1.这种方法使用了Function构造函数,把参数列表和函 ...
- shitf+tab
在eclipse中,shitf+tab可以使代码向左移动.
- 报表研究之PPT篇
PPT是一种说服力,是展示,也是营销. PPT写的好,会有事半功倍的效果. 写好PPT,重要的有以下几点. 1.1页1主题,1行1观点 2.善用图形,图成逻辑 3.微软雅黑最佳,其余字体配搭 4.色同 ...
- web自动化:DOM对象
一. 什么是DOM对象 定义:DOM(Document Object Mode,文档对象模型)是一套web标准,定义了访问HTML文档的一套属性.方法和事件 本质:网页与脚本语言沟通的桥梁.脚本语言通 ...
- java 文件类 null与exists()是不一样的
java 文件类 null与exists()是不一样的File imageFile0A=null; (imageFile0A==null)与!imageFile0A.exists() 不等价! 一个文 ...
- 64位Navicat Premium安装/破解【含资源】
开门见山: 1/先安装Navicat Primium,双击Navicat Primium——trial_64.exe(64位) 2/安装好打开Navicat Primium,提示使用或注册时,双击Pa ...
- winform使用相对路径读取文件的方法
获取exe文件的路径进行截取,分两次进行,然后拼接文件名,形成全路径 代码如下: string haarXmlPath = @"haarcascade_frontalface_alt_tre ...
- BEC listen and translation exercise 9
You will do foolish things, but do them with enthusiasm. 你难免会做傻事,但要做,就做得满怀激情. In addition, there sho ...