一、struts2中的拦截器(框架功能核心)

1、过滤器VS拦截器

过滤器VS拦截器功能是一回事。

过滤器是Servlet规范中的技术,能够对请求和响应进行过滤。

拦截器是Struts2框架中的技术。实现AOP(面向切面)的编程思想。是可插拔的, 能够对訪问某个 Action 方法之前或之后实施拦截。

拦截器栈(Interceptor Stack): 将拦截器按一定的顺序联结成一条链. 在訪问被拦截的方法时, Struts2拦截器链中的拦截器就会按其之前定义的顺序被依次调用

Struts2运行原理 - 底层分析

2、自己定义拦截器

struts2定义了一个拦截器接口Interceptor接口。

Interceptor接口里面有三个抽象方法

  • init: 该方法将在拦截器被创建后马上被调用, 它在拦截器的生命周期内仅仅被调用一次. 能够在该方法中对相关资源进行必要的初始化
  • interecept: 每拦截一个动作请求, 该方法就会被调用一次.
  • destroy: 该方法将在拦截器被销毁之前被调用, 它在拦截器的生命周期内也仅仅被调用一次.

    Struts 会依次调用程序猿为某个 Action 而注冊的每个拦截器的 interecept 方法.每次调用 interecept 方法时, Struts 会传递一个 ActionInvocation 接口的实例.

ActionInvocation: 代表一个给定动作的运行状态, 拦截器能够从该类的对象里获得与该动作相关联的 Action 对象和 Result 对象. 在完毕拦截器自己的任务之后, 拦截器将调用 ActionInvocation 对象的 invoke 方法前进到 Action 处理流程的下一个环节.

还能够调用 ActionInvocation 对象的 addPreResultListener 方法给 ActionInvocation 对象 “挂” 上一个或多个 PreResultListener 监听器. 该监听器对象能够在动作运行完毕之后, 開始运行动作结果之前做些事情

自己定义拦截器步骤:

a、编写一个类。实现com.opensymphony.xwork2.interceptor.Interceptor接口,或者继承

com.opensymphony.xwork2.interceptor.AbstractInterceptor类。(适配器模式),一般都选择继承AbstractInterceptor(拦截器会驻留内存)。

由于AbstractInterceptor 类实现了 Interceptor 接口. 并为 init, destroy 提供了一个空白的实现

编写两个拦截器InterceptorDemo1 ,和InterceptorDemo2

package com.itheima.interceptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor; public class InterceptorDemo1 extends AbstractInterceptor {
//动作的每次訪问都会调用该方法
public String intercept(ActionInvocation invocation) throws Exception {
System.out.println("拦截前Demo1");
String rtvalue = invocation.invoke();//放行,这里为什么返回string?
由于终于的结果返回的Action的Result。而action的结果是string类型
System.out.println("拦截后Demo1");
return rtvalue;
} }
package com.itheima.interceptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.interceptor.PreResultListener; public class InterceptorDemo2 extends AbstractInterceptor {
//动作的每次訪问都会调用该方法
public String intercept(ActionInvocation invocation) throws Exception { // invocation.addPreResultListener(new PreResultListener() {
//
// public void beforeResult(ActionInvocation invocation, String resultCode) {
// System.out.println("结果显示前");
// }
// }); System.out.println("拦截前Demo2");
String rtvalue = invocation.invoke();//放行
System.out.println("拦截后Demo2");
return rtvalue;
} }

b、须要在struts.xml中进行定义,定义拦截器,先定义在使用。

<package name="p1" extends="struts-default">
<!-- 定义拦截器:仅仅对当前包有效 -->
<interceptors>
<interceptor name="interceprotDemo1" class="com.itheima.interceptor.InterceptorDemo1"></interceptor>
<interceptor name="interceprotDemo2" class="com.itheima.interceptor.InterceptorDemo2"></interceptor>
</interceptors> </package>

c、在动作配置中就能够使用了

<action name="action1" class="com.itheima.action.Demo1Action" method="execute">
<!-- 使用定义的拦截器。如过没有指定不论什么的拦截器,默认使用default-stack栈中的全部拦截器。
一旦指定了不论什么一个拦截器,默认的就无效了
-->
<interceptor-ref name="interceprotDemo1"></interceptor-ref>
<interceptor-ref name="interceprotDemo2"></interceptor-ref>
<result>/success.jsp</result>
</action>

实现动作类Demo1Action

package com.itheima.action;

import com.opensymphony.xwork2.ActionSupport;

public class Demo1Action extends ActionSupport {

    @Override
public String execute() throws Exception {
System.out.println("execute运行了");
return SUCCESS;
} }

运行结果

由于struts2中如文件上传。数据验证,封装请求參数到action等功能都是由系统默认的defaultStack中的拦截器实现的,所以我们定义的拦截器须要引用系统默认的defaultStack,这样应用才干够使用struts2框架提供的众多功能。

如过没有指定不论什么的拦截器。默认使用default-stack栈中的全部拦截器;一旦指定了不论什么一个拦截器,默认的就无效了除了要使用自己定义的拦截器之外,还要使用defaultStack,能够这么办

方法一:(自己使用),仅仅需在action中配置自己定义的和defaultStack默认的就能够了。

方法二:(大家都用的时候),假设希望包下的全部action都使用自己定义的拦截器, 要使用拦截器栈 interceptor-stack,定义一个interceptor-stack。然后在action中能够通过<default-interceptor-ref name=“mydefaultStack”/>把拦截器定义为默认拦截器,mydefaultStack名字能够自己取。

<interceptors>
<interceptor name="interceprotDemo1" class="com.itheima.interceptor.InterceptorDemo1"></interceptor>
<interceptor name="interceprotDemo2" class="com.itheima.interceptor.InterceptorDemo2"></interceptor>
<interceptor-stack name="mydefaultStack">
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="interceprotDemo1"></interceptor-ref>
<interceptor-ref name="interceprotDemo2"></interceptor-ref>
</interceptor-stack>
</interceptors>
<action name="action3" class="com.itheima.action.LoginAction" method="login">
<interceptor-ref name="mydefaultStack"></interceptor-ref>
<result>/success.jsp</result>
</action>

3、Struts2 自带的拦截器

案例1:检查用户是否登录

1、 编写页面login.jsp

  <body>
<form action="${pageContext.request.contextPath}/login.action" method="post">
<input type="text" name="username"/><br/>
<input type="text" name="password"/><br/>
<input type="submit" value="登录"/>
</form>
</body>

2、编写登录校验的拦截器LoginCheckInterceptor 类

package com.itheima.interceptor;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor; public class LoginCheckInterceptor extends AbstractInterceptor { public String intercept(ActionInvocation invocation) throws Exception {
HttpSession session = ServletActionContext.getRequest().getSession();//通过ServletActionContext对象获得session对象
Object user = session.getAttribute("user");
if(user==null){
//没有登录
return "login";//返回到某个逻辑视图
}
return invocation.invoke();//放行
} }

3、编写配置文件struts.xml

<package name="p2" extends="struts-default">
<interceptors>
<interceptor name="loginCheckInterceptor" class="com.itheima.interceptor.LoginCheckInterceptor"></interceptor>
<interceptor-stack name="mydefaultStack">
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="loginCheckInterceptor"></interceptor-ref>
</interceptor-stack>
</interceptors>
<action name="login" class="com.itheima.action.CustomerAction" method="login">
<result>/login.jsp</result>
</action>
</package>

4、编写动作类CustomerAction

package com.itheima.action;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

public class CustomerAction extends ActionSupport {
public String login(){
System.out.println("登录");
ServletActionContext.getRequest().getSession().setAttribute("user", "ppp");
return SUCCESS;
}
}

案例2:监測动作方法的运行效率

编写时间监測过滤器TimerInterceptor

package com.itheima.interceptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor; public class TimerInterceptor extends AbstractInterceptor { public String intercept(ActionInvocation invocation) throws Exception {
long time = System.nanoTime();
String rtvalue = invocation.invoke();
System.out.println(rtvalue+"运行耗时:"+(System.nanoTime()-time)+"纳秒");
return rtvalue;
} }

编写配置文件

<package name="p2" extends="struts-default">
<interceptors>
<interceptor name="loginCheckInterceptor" class="com.itheima.interceptor.LoginCheckInterceptor"></interceptor>
<interceptor name="timerInterceptor" class="com.itheima.interceptor.TimerInterceptor"></interceptor>
<interceptor-stack name="mydefaultStack">
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="loginCheckInterceptor"></interceptor-ref>
<interceptor-ref name="timerInterceptor"></interceptor-ref>
</interceptor-stack>
</interceptors>
<result name="login">/login.jsp</result>
</action>
</package>

从上面能够看出。在一个action 中能够配置多个过滤器。

4、自己定义拦截器:能够指定拦截的方法或不拦截的方法

能够指定拦截的方法或不拦截的方法。编写过滤器时。能够实现类MethodFilterInterceptor。里面有两个字段,通过注入參数就能够指定那些不拦截。两个參数仅仅要用一个就可以,当拦截较少是,能够用includeMethods ,当拦截较多是。能够用排除的方法excludeMethods 。

excludeMethods = Collections.emptySet();//排除那些
includeMethods = Collections.emptySet();//包含那些

案例:再续登录校验的样例。

1、编写过滤器LoginCheckInterceptor

package com.itheima.interceptor;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor; public class LoginCheckInterceptor extends MethodFilterInterceptor {
protected String doIntercept(ActionInvocation invocation) throws Exception {
HttpSession session = ServletActionContext.getRequest().getSession();
Object user = session.getAttribute("user");
if(user==null){
//没有登录
return "login";//返回到某个逻辑视图
}
return invocation.invoke();//放行
} }

2、编写配置文件

3、编写动作类CustomerAction

package com.itheima.action;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

public class CustomerAction extends ActionSupport {
public String add(){
System.out.println("调用add的service方法");
return SUCCESS;
}
public String edit(){
System.out.println("调用edit的service方法");
return SUCCESS;
}
public String login(){
System.out.println("登录");
ServletActionContext.getRequest().getSession().setAttribute("user", "ppp");
return SUCCESS;
}
}

4、编写页面

addCustomer.jsp

 <body>
加入客户
</body>

editCustomer.jsp

  <body>
改动客户
</body>

login.jsp

  <body>
<form action="${pageContext.request.contextPath}/login.action" method="post">
<input type="text" name="username"/><br/>
<input type="text" name="password"/><br/>
<input type="submit" value="登录"/>
</form>
</body>

success.jsp

  <body>
oyeah
</body>

二、文件上传与下载

Struts2开发的三板斧。页面jsp—配置文件struts2.xml—-还有动作类Action

文件上传前提:

form表单的method必须是post

form表单的enctype必须是multipart/form-data

提供type=”file”的上传输入域

Struts 对文件上传的支持的一些规则

1、单文件上传

开发步骤:

1、在WEB-INF/lib下加入commons-fileupload-1.2.1.jar、commons-io-1.3.2.jar。这两个文件能够从http://commons.apache.org/下载

2、第二步:编写upfile.jsp ,把form表的enctype设置为:“multipart/form-data“,例如以下:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<body>
<s:actionerror/>
<hr/>
<s:fielderror></s:fielderror>
<form action="${pageContext.request.contextPath}/upload1.action" method="post" enctype="multipart/form-data"><!-- 以MIME的方式传递
-->
用户名:<input type="text" name="username"/><br/>
靓照:<input type="file" name="photo"/><br/>
<input type="submit" value="上传"/>
</form>
</body>

编写错误页面error.jsp

 <body>
server忙,一会再试。 </body>

success.jsp

  <body>
上传成功
</body>

3、编写UploadAction1 类:在Action类中加入属性,属性相应于表单中文件字段的名称:

package com.itheima.actions;

import java.io.File;
import java.io.IOException; import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionSupport;
//文件上传:fileUpload拦截器完毕的
public class UploadAction1 extends ActionSupport { private String username;
private File photo;//和表单的上传字段名保持一致。 类型是File类型的
private String photoFileName;//上传的文件名称
private String photoContentType;//上传文件的MIME类型 //省略getter和setter方法
public String upload(){
System.out.println(photoFileName+":"+photoContentType);
//普通字段:
System.out.println(username);
//上传字段:上传到某个文件夹。存到应用的images文件夹下
String realPath = ServletActionContext.getServletContext().getRealPath("/images");
File directory = new File(realPath);
if(!directory.exists()){
directory.mkdirs();
}
try {
FileUtils.copyFile(photo, new File(directory, photoFileName));
return SUCCESS;
} catch (IOException e) {
e.printStackTrace();
return ERROR;
} }
}

在struts.xml文件里添加例如以下配置

<action name="upload1" class="com.itheima.actions.UploadAction1" method="upload">
<interceptor-ref name="defaultStack">
<param name="fileUpload.allowedTypes">image/jpeg,image/png</param>
<param name="fileUpload.allowedExtensionsSet">jpg,jpeg,png</param>
</interceptor-ref>
<result>/success.jsp</result>
<result name="error">/error.jsp</result>
<result name="input">/index.jsp</result>
</action>

原理分析:

a 、FileUpload 拦截器负责处理文件的上传操作, 它是默认的 defaultStack 拦截器栈的一员. 拦截器有 3 个属性能够设置.

  • maximumSize: 上传文件的最大长度(以字节为单位), 默认值为 2 MB
  • allowedTypes: 同意上传文件的类型, 各类型之间以逗号分隔
  • allowedExtensions: 同意上传文件扩展名, 各扩展名之间以逗号分隔

    能够在 struts.xml 文件里覆盖这 3 个属性

b、超出大小或非法文件的上传,会报错(转向一个input的视图)

通过:

<s:actionError/> <s:feildError/>显示错误消息的提示

c、错误消息提示改为中文版:借助国际化的消息资源文件

假设是通过配置全局默认參数引起的错误。最好用全局的消息资源文件。

struts2默认的提示资源文件:struts2-core-**.jar 的org.apache.struts2的struts-message.properties文件里。

比着key值覆盖相应的value就可以。

配置例如以下:

struts.messages.error.uploading=Error uploading: {0}
struts.messages.error.file.too.large=File too large: {0} "{1}" "{2}" {3}
struts.messages.error.content.type.not.allowed=Content-Type not allowed: {0} "{1}" "{2}" {3}
struts.messages.error.file.extension.not.allowed=File extension not allowed: {0} "{1}" "{2}" {3}

{0}:<input type=“file” name=“uploadImage”>中name属性的值

{1}:上传文件的真实名称

{2}:上传文件保存到暂时文件夹的名称

{3}:上传文件的类型(对struts.messages.error.file.too.large是上传文件的大小)

源代码:

改动显示错误的资源文件的信息

第一步:创建新的资源文件 比如fileuploadmessage.properties,放置在src下
在该资源文件里添加例如以下信息
struts.messages.error.uploading=上传错误: {0}
struts.messages.error.file.too.large=上传文件太大: {0} "{1}" "{2}" {3}
struts.messages.error.content.type.not.allowed=上传文件的类型不同意: {0} "{1}" "{2}" {3}
struts.messages.error.file.extension.not.allowed=上传文件的后缀名不同意: {0} "{1}" "{2}" {3} 第二步:在struts.xml文件载入该资源文件 <!-- 配置上传文件的出错信息的资源文件 -->
<constant name="struts.custom.i18n.resources" value=“cn….xxx.fileuploadmessage“/>

2、多文件上传

上传多个文件, 能够使用数组或 List,其它和单文件上传相似。

package com.itheima.actions;

import java.io.File;
import java.io.IOException; import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionSupport;
//文件上传:fileUpload拦截器完毕的
public class UploadAction2 extends ActionSupport { private String username;
private File[] photo;//和表单的上传字段名保持一致。类型是File类型的 .数组或List
private String[] photoFileName;//上传的文件名称
private String[] photoContentType;//上传文件的MIME类型 public String upload(){
//上传字段:上传到某个文件夹。 存到应用的images文件夹下
String realPath = ServletActionContext.getServletContext().getRealPath("/images");
File directory = new File(realPath);
if(!directory.exists()){
directory.mkdirs();
}
try {
for(int i=0;i<photo.length;i++){
FileUtils.copyFile(photo[i], new File(directory, photoFileName[i]));
}
return SUCCESS;
} catch (IOException e) {
e.printStackTrace();
return ERROR;
} }
}

3、文件下载

原理:struts2提供了stream结果类型,该结果类型就是专门用于支持文件下载功能的

指定stream结果类型 须要指定一个 inputName參数。该參数指定一个输入流。提供被下载文件的入口

编码步骤:

1、动作类DownloadAction :

package com.itheima.actions;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.net.URLEncoder; import org.apache.commons.io.FilenameUtils;
import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionSupport; public class DownloadAction extends ActionSupport {
private InputStream image;//用in有问题的
private String filename;//文件名称
private long filesize;
public InputStream getImage() {
return image;
} public void setImage(InputStream image) {
this.image = image;
} public String getFilename() {
return filename;
} public long getFilesize() {
return filesize;
} public String download() throws Exception{
//给image字节流赋值
String fileRealPath = ServletActionContext.getServletContext().getRealPath("/WEB-INF/classes/霉女.jpg");
filename = FilenameUtils.getName(fileRealPath);
//方式一:中文文件要进行URL编码
// filename = URLEncoder.encode(filename, "UTF-8");
filesize = new File(fileRealPath).length();
System.out.println(filename);
image = new FileInputStream(fileRealPath);
return SUCCESS;
}
}

struts.xml配置文件:主要是对stream类型的结果进行配置

<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.ognl.allowStaticMethodAccess" value="true" />
<action name="download" class="com.itheima.actions.DownloadAction" method="download">
<result type="stream"> <param name="inputName">image</param><!--动作类中InputStream的字段名,须要在Action中提供getTargetFile方法,返回inputStream-->
<param name="contentType">application/octet-stream</param><!--告诉浏览器响应头。文件的MIME格式,调用Action中的getContentType方法-->
<!-- 在struts.xml中使用OGNL表达式获取动作类中属性的值。 调用动作类中的 getFilename()-->
<!-- 中文文件名称编码:方式二.使用OGNL表达式,调用URLEncode的静态方法 -->
<!-- 默认OGNL调用静态方法是不行的,须要开启一个常量开关.struts.ognl.allowStaticMethodAccess=true -->
<param name="contentDisposition">attachment;filename=${@java.net.URLEncoder@encode(filename,'UTF-8')}</param><!-- 告诉浏览器的下载方式-->
<param name="contentLength">${filesize}</param>
</result>
</action>
</package>
</struts>

拦截器和文件上传就写到这里了。好累!

深入分析JavaWeb Item47 -- Struts2拦截器与文件上传下载的更多相关文章

  1. 利用Struts2拦截器完成文件上传功能

    Struts2的图片上传以及页面展示图片 在上次的CRUD基础上加上图片上传功能 (https://www.cnblogs.com/liuwenwu9527/p/11108611.html) 文件上传 ...

  2. Struts2学习第四天——拦截器及文件上传

    1.概述 Struts2的很多核心功能都是由拦截器完成的. 拦截器很好的实现了AOP的编程思想,在动作的执行之前和结果的返回之后,做拦截处理. 2.struts2的默认拦截器栈 3.自定义拦截器 St ...

  3. Spring MVC—拦截器,文件上传,中文乱码处理,Rest风格,异常处理机制

    拦截器 文件上传 -中文乱码解决 rest风格 异常处理机制 拦截器 Spring MVC可以使用拦截器对请求进行拦截处理,用户可以自定义拦截器来实现特定的功能,自定义的拦截器必须实现HandlerI ...

  4. Struts2配合layui多文件上传--下载

    先说上传: 前台上传文件的js代码: var demoListView = $('#demoList') ,uploadListIns = upload.render({ elem: '#testLi ...

  5. springMVC学习记录3-拦截器和文件上传

    拦截器和文件上传算是springmvc中比较高级一点的内容了吧,让我们一起看一下. 下面先说说拦截器.拦截器和过滤器有点像,都可以在请求被处理之前和请求被处理之到做一些额外的操作. 1. 实现Hand ...

  6. SpringBoot入门一:基础知识(环境搭建、注解说明、创建对象方法、注入方式、集成jsp/Thymeleaf、logback日志、全局热部署、文件上传/下载、拦截器、自动配置原理等)

    SpringBoot设计目的是用来简化Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置.通过这种方式,SpringBoot致力于在蓬勃发 ...

  7. Struts2 文件上传,下载,删除

    本文介绍了: 1.基于表单的文件上传 2.Struts 2 的文件下载 3.Struts2.文件上传 4.使用FileInputStream FileOutputStream文件流来上传 5.使用Fi ...

  8. JavaWeb实现文件上传下载功能实例解析

    转:http://www.cnblogs.com/xdp-gacl/p/4200090.html JavaWeb实现文件上传下载功能实例解析 在Web应用系统开发中,文件上传和下载功能是非常常用的功能 ...

  9. JAVA Web 之 struts2文件上传下载演示(一)(转)

    JAVA Web 之 struts2文件上传下载演示(一) 一.文件上传演示 1.需要的jar包 大多数的jar包都是struts里面的,大家把jar包直接复制到WebContent/WEB-INF/ ...

随机推荐

  1. Hadoop Hive概念学习系列之hive里如何显示当前数据库及传参(十九)

    这个小知识点,看似简单,用处极大. $ hive --hiveconf hive.cli.print.current.db=true $ hive --hiveconf hive.cli.print. ...

  2. Js控制样式的诸多方法

    function TableCss(options){ //如果没参数,就退出 if(arguments.length < 1 || !document.getElementById(optio ...

  3. MVC系列学习(十)-生成URL与表单

    本次学习,在路由配置信息中,有两个路由规则,在网站第一次启动的时候,注册了两个路由表 1.动态生成url A.在路由规则中,因为Default在前面,所以最新找到该路由表,此时不管 自己定义的控制器名 ...

  4. 关于华为手机Log.d打印不出来log的问题

    http://blog.csdn.net/picasso_l/article/details/52489560     拨号,进入后台设置,进行操作.

  5. html5——伸缩布局

    基本概念 1.主轴:Flex容器的主轴主要用来配置Flex项目,默认是水平方向 2.侧轴:与主轴垂直的轴称作侧轴,默认是垂直方向的 3.方向:默认主轴从左向右,侧轴默认从上到下 4.主轴和侧轴并不是固 ...

  6. php入门学习相关函数

      1.join(): 定义和用法 join() 函数返回由数组元素组合成的字符串. join() 函数是 implode() 函数的别名. 注释:join() 函数接受两种参数顺序.但是由于历史原因 ...

  7. 使用NSSM将Kibana安装为Windows服务

    Kibana不同于Elasticsearch,前者官方并没有提供安装为系统服务的方法,如果直接运行在生产环境中会尤为麻烦,一旦服务器因故重启就要手动开启,所以将Kibana安装为系统服务非常有必要. ...

  8. CStatic设置位图

    CStatic 用于显示位图 如果要显示图标,则必须要设置窗口属性为 SS_BITMAP 和 SS_CENTERIMAGE,实例代码如下: //获得指向静态控件的指针 CStatic *pStatic ...

  9. ARX自定义实体

    本文介绍了构造自定义实体的步骤.必须继承的函数和必须注意的事项 1.新建一个从AcDbEntity继承的类,如EntTest,必须添加的头文件: "stdarx.h"," ...

  10. 总结这几天js的学习内容

    对js中难点的理解 1.把变量对象像遍历数组一样简单 对于数组 ,迭代出来的是数组元素,对于对象 ,迭代出来的是对象的属性: var obj = { w: "wen", j: &q ...