📄 复习1.txt
字号:
灵活
适合大型
需求模糊的系统
缺:
太灵活无法保证质量
3、统一软件开发流程(rup):有四大阶段六大流程,每一个阶段
都会执行六大流程。每一个阶段所执行流程的侧重不一样。
四大阶段:
启动:侧重于需求
精化:设计
构建:编码
产品化:部署
六大流程:
业务建模:找业务实体及业务实体之间的关系
需求:
分析设计
实施:编码
测试:
部署
4、极限编程(xp):
侧重点:
1、有效的沟通胜过合同谈判
2、高质量的代码胜过面面俱到的文档
3、成对开发
4、迭代
jsp&servlet
1、jdbc中的核心类
Class.forName("com.microsoft.");//注册驱动
DriverManager:得到连接
Connection con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;databaseName=pubs;selectMethod=cursor","用户",“密码”);
Connection:一个连接会话,可以得执行sql的对象
--执行dml(insert update delete)
PreparedStatement ps=con.preparedStatement("insert into student values(?,?,?)");
ps.setString(1,"张三");
ps.executeUpdate();
Statement st=con.createStatement();
--执行查询
st.executeQuery("select * from student");
--执行dml(insert update delete)
st.executeUpdate("insert into student values('cc','cc','x','s')");
--执行查询
PreparedStatement ps=con.preparedStatement("select * from student");
ResultSet rs=ps.executeQuery();
PreapredStatement、Statement的区别
PreparedStatement:
可以动态传参
在得到PreparedStatement实例时,要给定sql,所以sql是预编译,重复执行时效率高。
Statement
不可以动态传参
在得到Statement实例时,不给定sql,sql不预编译,重复执行时效率低。
2、如何实现一个servlet
1、继承于HttpServlet,实现doGet及doPost方法
public class MyServlet extends HttpServlet
{
//form中的method=get时或超链时调用doGet方法
//doGet的信息写在请求的url中,不安全,传输的信息少
//如果是表单一般用doPost方法
public void doGet(HttpServletRequest request,HttpServletResponse response)
{
request:客户的请求及表单域信息
//表表单域信息
String userName=request.getParameter("表单域名");
String like[]=request.getPrameterValues("重复的表单域名");
//在request中加入对象,转发到另一页面时可以重用
request.setAttribute("名称","对象");
request.getAttribute("名称");
//转发到另一个servlet或jsp页面,会通过参数将当前servlet或jsp中的request
response传入到另一个页面
request.getRequestDispatch("a.jsp").forward(request,response);
//得到session
HttpSession session=request.getSession();
response:是响应信息
//得到输出流,向客户端打印文本
PrintWriter pw=response.getWriter();response.getOutputStream();
pw.println("<h1>helloworld</h1>");
//跳转:下一个页面或servlet不保留上一个页面的request、respose对象。
response.sendRedirect("a.jsp");
}
//form中的method=post时调用
//doPost的信息写在http请求的正文中,安全,传输的信息大
//如果是表单一般用doPost方法
public void doPost(HttpServletRequest request,HttpServletResponse response)
{
}
}
在web.xml部署
<servlet>
<servlet-name>myServler</serlvet-name>
<servlet-class>servlet.MyServlet</servlet-claass>
</servlet>
<servlet-mapping>
<servlet-name>myServler</serlvet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
3、转发、跳转、提交、超链的区别
转发:运行在服务端,下一页面保留当前页面的request、response
跳转:运行在服务端,下一页面不保留当前页面的request、response
提交:运行在客户端,向服务器发送请求,提交表单域的内容
超链:运行在客户端,向服务器发送请求,提交超链信息
4、jsp中的九大内置对象
request:HttpServletRequest,转发到下一个页面时可以重用对象
response:客户端响应
session:HttpSession,一个用户多个页面共享同一变量。
application:ServletContext,多个用户多个页面共享同一变量。
pageContext:jsp页面的运行环境,在自定义标签中用的很多,
可以得到另外8大对象
pageContext.getRequest();
pageContext.getApplication();
--转发到另一个页面
pageContext.forword("a.jsp");
request.getRequestDispatch("a.jsp").forward(request,response);
out:向客户端打印文本
out.println("<h1></h1>");
exception:只在异常页面中,正常页面出错时跳到异常页面,通过异常
页面显示错误。
异常页面(error.jsp)
<%@page isErrorPage="true"%>
exception.getMessage();
正常页面(common.jsp):
<%@page errorPage="error.jsp"%>
page:当前页面定义变量当前页面有效,作用域最小
config:ServletConfig的实例
5、servlet的体系结构
Servlet接口
GenericServlet通过用Servlet可以跨协议
HttpServlet:只适用到http协议
自定义Servlet,必须继承于HttpSerlvet
6、servlet生命周期
1、单例
2、3个方法
init:初始化时调用,只调用一次
service:每请求一次调用一次
doGet
doPost
destroy:销毁时调用,只调用一次
7、动作:
<jsp:forward page="sucess.jsp"/>转发到另一个页面
<jsp:include page=""/>导入另一个页面的运行结果
<jsp:userBean id="" class="" scope="request/session/application"/>
有则用已有的,没有则产生一个新的
<jsp:setProperty name="" property="" value=""/>:向一个对象的一个属性设值
<jsp:getProperty name="" property=""/>:打印一个对象的属性值
8、指令
<@page import="" contentType="text/html;charset=utf-8"
isErrorPage="false/true" errorPage="error.jsp"/>
<@taglib uri="" prefix=""/>//引入标签库
<@include file=""/>//将两个页面个在一起形成一个文件,编译成
class运行。
9、model2(MVC)的处理过程
MVC
M(model):
StudentPersistent(Dao)
V(view)
jsp
c(control)
Servlet
请求处理过程:
jsp--->serlvet-->studentPersistent
studentPersistent-->servlet--jsp
10、model2的作用:
让模型与视图强制解藕,相当到旅店的服务员,提高了
代码的可扩展、可维护
11、el语言及jstl标签
显示信息
${requestScope/sessionScope/applicationScope.user.userName}
循环
<c:foreach items="${requestScope.users}" var="user">
${user.userName}
</c:foreach>
判断:
<c:if test=${requestScope.user.userName=='a'}>
</c:if>
在jsp页面中不出现任何的%,只有el及标签,这样页面没有任何逻辑
只有显示作用。
12、过滤类的作用:是一个拦截器可在拦截所有的请求,在调用jsp或servlet之前
执行,jsp或serlvet执行完后过滤再次过滤处理。相当于门,进
与出时都可过滤处理。
public class MyFilter implements Filter
{
public void doFilter(HttpServletRequest request,HttpServletResponse response,Filter filte)
{
request.setCharactorSet("utf-8");
filter.doFilter(request,response);//给真正的处理者
System.out.println("aaaaaaaaaaaaaaa");
}
}
<filter>
<filter-name>code</filter-name>
<filter-class>aa.MyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>code</filter-name>
<url-pattern>/*.do</url-pattern>
</filter-mapping>
struts1
1、struts的MVC分别代表那些类?
M:业务+dao+持久
V:jsp actionForm
C:
ActionServlet
RequestProcessor
Action
ActionMapping
ActionForward
2、struts的请求处理过程?
url.do将请求发给ActionServlet
ActionServlet转发给RequestProcessor
RequestProcessor根所url在struts-config.xml找到对应的Action及ActionForm
如果在相关的作用域中存在ActionForm,RequestProcessor用已有的,如果不存,
RequestProcesor实例化一个新的,并通过类的返射将表单域的值注入到ActionForm中
如果存在Action,RequestProcessor用已有的,如果不存在实例化一个新的Action并
调用Action的execute方法。
execute方法执行结束时通过ActionMapping找到一个ActionForward转发到另一个jsp页面。
3、struts原理
struts的核心类是ActionServlet,其可以接收所有.do结尾的请求。
核心配置文件是struts-config.xml文件说明url与Action及ActionForm的对应关系,
url不可以重复。
在web.xml中说明ActionServlet、其可以接收所有以do结尾的请求;
说明struts-config.xml所在位置,以参数的形式传给ActionServlet。
当启动容器时,容器(tomcat、weblogic)实例化ActionServlet,初始化
ActionServlet,在初始化ActionServlet时加载struts-config.xml文件。
当客户通过url.do将请求发给ActionServlet,ActionServlet将处理
转发给助手RequestProcessor,RequestProcess通过struts-config.xml
找到对应的actionForm及action,如果有ActionForm用已有的,没有
通过类的反射实例化ActionForm,通过反射将表单域的值填充到actionForm中。
如果有Action用已有的,没有产生一个新的,通过反射调用action的
execute方法,在执行前将actionForm通过参数注入到execute方法中,
execute 方法执行结束前通过actionMapping找到actionForward转发到
另一个页面。
4、RequestProcessor的处理过程
processPath() 确定选择将要处理的动作的路径
processMapping() 为请求选择动作映射
<action path="/login" type="struts.action.LoginAction"
name="userForm" attribute="userForm"
scope="session" input="/login.jsp" validate="true"
>
<forward name="success" path="/succ.jsp"/>
<forward name="error" path="/error.jsp"/>
</action>
processActionForm() 新建一个 Form Bean 或从请求会话中检索 Form Bean
processPopulate() 填充与请求关联的 ActionForm
processForward() 处理 <action-mapping> 元素的 forward 以匹配当前的请求路径
processValidate() 调用 Form Bean 的 validate() 方法
processActionCreate() 实例化当前 ActionMapping 指定的类的实例
processActionPerform() 将调用 action 的 perform() 或 execute() 方法 processPreprocess()
告诉请求处理器调用此方法后是否应继续处理请求
5、struts的标签库
<html>
<html:select property="">
<html:options/>
</html:select>
<html:radio>
<html:mulitibox value="" property="字符串数组">
1、错误返回的页面可以保留以前的值。
2、前一个action产生的form如果在request或session中,
转发到另一个jsp页面,jsp页面所用的form与前一个action
所用的form名及类型相同可以直接显示
<bean>
<bean:define name="" id="" scope=""/>
从scope中取出name放到变量id中。
<bean:define id="" scope="" name="" property="属性名"/>
从scope中取出name的property属性放到变量id中。
<bean:write name="" property=""/>
将对象name的值打印。
<bean:message key=""/>
通过键名取国际化的值
<logic>
<logic:iterator id="" scope="" name="" />
从scope中取出集合name将其每一个元素放到id中。
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -