软件工程综合实践心得(2)

MVC 

Model  模型层   实体类 

View    视图层    jsp   html

Controller  控制层      servelt(实现了前后台的交互) 

 

LoginAction  到底做了什么?

  1. 通过String username = request.getParameter("username");

获取了页面当中输入的用户名

  1. 有可能获取到乱码,那可以通过

username = new String (username.getBytes("ISO-8859-1"),"utf-8");

转码   如果 获取的信息不是乱码,那你就不要转码了,否则会转换成乱码

  1. 判断一下是否能登陆(获取的用户名和密码是否都匹配)

if("neusoft".equals(username)&&"123".equals(pwd))

  1. WEB-INF下的jsp页面不能直接跳转,需要通过

request.getRequestDispatcher("WEB-INF/jsp/success.jsp").forward(request, response);

转发,才能够跳转

  1.  request.getRequestDispatcher 可以携带  request.setAttribute的信息
  2.  Request转发之后的页面,可以通过el表达式获取setAttribute的信息

${uname }     注意  uname  是 

request.setAttribute("uname", username);这个方法中的uname

  1. Response 是  重定向,不能携带数据
  2. Session里面的数据  response 和  request 都能传递

 

 

Springmvc.xml

<beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"

    xmlns:context="http://www.springframework.org/schema/context"

    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"

    xsi:schemaLocation="http://www.springframework.org/schema/beans

       http://www.springframework.org/schema/beans/spring-beans-3.2.xsd

       http://www.springframework.org/schema/mvc

       http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd

       http://www.springframework.org/schema/context

        http://www.springframework.org/schema/context/spring-context-3.2.xsd

       http://www.springframework.org/schema/aop

       http://www.springframework.org/schema/aop/spring-aop-3.2.xsd

       http://www.springframework.org/schema/tx

       http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">

 

<!-- 配置Controller -->

<bean id="UsersController1" name="/users.action" class="cn.neusoft.controller.UsersController1"></bean>

 

<!-- 项目中一般使用 扫描包的方式 进行  配置 -->

<context:component-scan base-package="cn.neusoft.controller"></context:component-scan>

 

<!-- 实际开发中使用    加载注解的  适配器、映射器  、   Json转换器      -->

<mvc:annotation-driven></mvc:annotation-driven>

posted @ 2017-07-02 17:28  FvU  阅读(113)  评论(0编辑  收藏  举报