Java开发工程师,Web方向 - 04.Spring框架 - 期末测试

Spring框架客观题

Spring框架编程题

http://blog.csdn.net/sinoacc/article/details/51702458

1

(25分)

假设有如下数据表:

create table Blog(

blogId int auto_increment primary key comment "博客Id",

blogTitle varchar(10) comment "博客标题",

blogContent varchar(100) comment "博客内容" )

ENGINE=InnoDB DEFAULT CHARSET=utf8;

提供一个发表博客的接口,可以通过POST方法(表单)提交两个参数,blogTitle,blogContent,类型为String,并且限制blogTitle长度20个英文字符,blogContent长度为100个英文字符(假设客户端传过来的内容都为英文字符),如果内容不符合长度要求,向客户端返回400响应码,如果符合长度要求,则将内容保存到Blog数据表中,并返回200响应码给客户端。

注:如果不熟悉HTML表单,可以参考http://www.w3school.com.cn/tags/tag_form.asp 。

答:

1. 新建Maven工程

2. 在src/main/webapps下创建index.html

2

(30分)

完成一个具有登陆功能的简单Web工程,要求:

1. 提供一个简单的登陆表单,用户可以输入用户名(userName),密码(userPassword),点击提交后登陆;

2. 后端提供一个登陆接口(login),可以判断用户是否是合法用户(从创建好的用户表中查询数据,可预先在数据库中插入几条数据);

3. 登陆成功后,显示用户信息页面(user),内容自定义,如显示用户名,并给出一个欢迎消息;

4. 如果未登陆用户直接访问用户信息页面(user),向客户端返回一个错误页面(error),内容自定义,如提示用户未登陆等。

注:

1. 建表及插入语句

create table User(

userId int auto_increment primary key comment "用户Id",

userName varchar(100) comment "用户名称",

userPassword varchar(100) comment "用户密码" )

ENGINE=InnoDB DEFAULT CHARSET=utf8;

insert into User (userName, userPassword) values ("test1", "test1")

insert into User (userName, userPassword) values ("test2", "test2")

上述语句插入两个用户test1及test2,密码分别为test1,test2

2. 需要用到cookie及session相关内容来检查当前请求是否为登陆用户的请求;