前段时间学习了mvc设计模式,并按照mvc模式设计了一个网页,在这个网页上我可以根据不同条件查询数据库的数据。
关于mvc是什么,以及采用mvc模式的作用,这篇博客讲的十分浅显易懂:
https://blog.csdn.net/muyi_amen/article/details/54341065
首先是显示主界面网页的jsp文件main.jsp.这是属于视图V这一部分的。这里把表单的处理方法设置为get,并在web.xml文件中注册好处理该action的类为MyServlet.java。代码内容如下:
<%@ page language="java" contentType="text/html; charset=utf-8" 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" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>世界杯信息查询</title>
</head>
<body>
<FONT SIZE="8" COLOR="颜色#FF0000"style="position:absolute; width:800px; height:415px;z-index:1;left: 600px;top:200px;">
世界杯信息查询
</FONT>
<form action="findu" method="get" style="position:absolute; width:800px; height:415px;z-index:1;left: 400px;top:300px;" >
<p>球员查询: 国家:<input type="text" name="country" style="width:40px" />
名字:<input type="text" name="pname" style="width:40px" />
号码:<input type="text" name="number" style="width:40px" />
位置:<input type="text" name="position" style="width:40px"/>
年龄:<input type="text" name="age" style="width:40px" />
惯用脚:<input type="text" name="footuse" style="width:40px" />
进球数:<input type="text" name="goal" style="width:40px"/>
<input name="find1" type="submit" value="查询球员"></p>
<p>比赛查询: 主队:<input type="text" name="hteam" style="width:40px"/>队
客队:<input type="text" name="gteam" style="width:40px"/>队
时间:<input type="text" name="month" style="width:40px" />月<input type="text" name="day" style="width:40px" />日
<input name="find" type="submit" value="查询比赛"> </p>
</form>
</body>
</html>
然后是充当控制器C的MyServlet.java.它的功能是流程控制,比如判断用户按下主界面网页哪个按钮以及输入了哪些值。并获取这些值传入模型