实验三 Struts2框架编程-实验报告纸 下载本文

内容发布更新时间 : 2024/5/21 6:09:55星期一 下面是文章的全部内容请认真阅读。

南京信息工程大学 实验(实习)报告

实验(实习)名称 Struts2框架编程 实验(实习)日期 得分 指导教师 院 计软 专业 计科 年级 2013级 班次 3 姓名 张文娇 学号 20131308081

1.实验目的:

1)掌握Struts2框架和工作流程。 2)熟悉Struts标签库的使用。

3)掌握Struts 2拦截器的原理,并能进行相关设置和编程。 4)了解和掌握文件上传等功能实现

2.实验内容:

1)采用Struts2框架,创建三个JSP页面(hello.jsp、welcome.jsp)和一个Action实现类(StrutsAction),并对web.xml和Struts.xml进行必要配置,实现用户登录功能的处理。(参考教材3.1节)

2)采用Struts2相关技术,实现“学生综合管理系统”的“添加学生信息”功能(具体需求详见教材3.7所述)

3.实验步骤

{对每个实验题目进行简要步骤描述,包括源码和实验结果截图} 1)

1.启动MyEclips 8.5

2.创建web project项目命名为FirstStruts2 3.添加支持包 4.配置web.xml

struts2.0

org.apache.struts2.dispatcher.FilterDispatcher

struts2.0 /*

5.在工程中创建LoginAction.jsp

import dao.CustomerDAO; public class LoginAction {

private String name; private String password; /**在此方法里实现业务逻辑处理*/

public String execute() throws Exception {

CustomerDAO dao=new CustomerDAO(); boolean boo=dao.check(name, password); if(boo)

return \

}

else

return \

public String getName() { return name; }

public void setName(String name) { this.name = name; } public String getPassword() { return password; }

public void setPassword(String password) {this.password = password;} }

6.配置struts.xml文件

\ \

/success.jsp /error.jsp

7.创建login.jsp

用户名:

密码:

8.创建success.jsp与error.jsp 9.连接MYSQL Enter password:

Welcome to the MySQL monitor. Commands end with ; or \\g. Your MySQL connection id is 1

Server version: 5.1.34-community MySQL Community Server (GPL)

Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement. mysql> create database mydb;

Query OK, 1 row affected (0.01 sec) mysql> use mydb; Database changed

mysql> create table customer( -> name char(20),

-> password char(20));

Query OK, 0 rows affected (0.08 sec)

mysql> insert into customer values('sa1','admin'); Query OK, 1 row affected (0.03 sec)

mysql> insert into customer values('kate','123'); Query OK, 1 row affected (0.02 sec)

mysql>

10.创建CustomerDAO

public class CustomerDAO {

public boolean check(String name,String password){ try{

Class.forName(\ Connection

con=DriverManager.getConnection(\

Statement state=con.createStatement();

String sql=\* from customer where name='\and password='\

ResultSet rs=state.executeQuery(sql); if(rs.next()){ return true; }

}catch(Exception e){ e.printStackTrace(); }

return false; } }