struts2 拦截器_Struts 2拦截器示例

struts2 拦截器

Welcome to Struts 2 Interceptor Example. While working on Struts 2, most of the time you will spend on Action Classes but Interceptors are the backbone of Struts 2 Framework.

欢迎使用Struts 2拦截器示例。 在Struts 2上工作时,大多数时候您将花在Action Class上,但是Interceptor是Struts 2 Framework的基础。

Struts 2拦截器 (Struts 2 Interceptor)

Struts 2 interceptors are responsible for most of the processing done by the framework. For example, passing request params to action classes, making Servlet API request, response, session available to Action classes, validation, i18n support etc.

Struts 2拦截器负责框架完成的大多数处理。 例如,将请求参数传递给动作类,使Servlet API请求,响应,会话可用于动作类,验证,i18n支持等。

Struts 2 provides a bunch of interceptors and most of them are defined in struts-default package and used in defaultStack interceptor stack. Interceptors are the power of Struts 2 framework that plays a crucial role in achieving high level of separation of concerns.

Struts 2提供了一堆拦截器,其中大多数是在struts-default包中定义的,并在defaultStack拦截器堆栈中使用。 拦截器是Struts 2框架的强大功能,在实现关注点的高度分离方面起着至关重要的作用。

In our Struts 2 Beginners Tutorial, we looked at the Struts 2 architecture and saw that every request and response passes through interceptors. Hence interceptors can inject different objects, perform specific operations on request and response and do some cross cutting tasks for the application.

在《 Struts 2初学者教程》中 ,我们研究了Struts 2架构,并看到每个请求和响应都通过拦截器传递。 因此,拦截器可以注入不同的对象,根据请求和响应执行特定的操作,并为应用程序执行一些交叉任务。

ActionInvocation is responsible to incapsulate Action classes and interceptors and to fire them in order. The most important method for use in ActionInvocation is invoke() method that keeps track of the interceptor chain and invokes the next interceptor or action. This is one of the best example of Chain of Responsibility pattern in Java EE frameworks.

ActionInvocation负责封装Action类和拦截器,并按顺序触发它们。 在ActionInvocation中使用的最重要的方法是invoke()方法,该方法跟踪拦截器链并调用下一个拦截器或操作。 这是Java EE框架中“责任链”模式的最佳示例之一。

Struts 2 API reads the interceptors defined for an action in the order it’s declared. So if interceptor1 and interceptor2 are defined for action1 then ActionInvocation will invoke them in following chain.

Struts 2 API按照声明的顺序读取为操作定义的拦截器。 因此,如果为action1定义了interceptor1和interceptor2,则ActionInvocation将在随后的链中调用它们。

interceptor1 -> interceptor2 -> action1 -> interceptor2 -> interceptor1

拦截器1->拦截器2->动作1->拦截器2->拦截器1

If any of the interceptor intercept() method decides that action should not get executed, it can return a string value and response will be created from global result with that name from struts configuration file.

如果任何拦截器intercept()方法确定不应执行该操作,则它可以返回一个字符串值,并且将从struts配置文件中具有该名称的全局结果中创建响应。

Struts 2拦截器和全局结果配置 (Struts 2 Interceptors and Global Results configuration)

We can define global results in struts.xml file as:

我们可以在struts.xml文件中将全局结果定义为:

<global-results>
	<result name="login" type="redirect">/login.action</result>
</global-results>

These results can be used by any of the action classes.

这些结果可以被任何动作类使用。

Defining interceptors for a package includes several steps and we need to define them with interceptors, interceptor, interceptor-stack and default-interceptor-ref elements. They should be the first elements of the package or else you will get error message as

为包定义拦截器包括几个步骤,我们需要使用拦截器,拦截器,拦截器堆栈和默认拦截器-ref元素对其进行定义。 它们应该是包的第一个元素,否则您将收到以下错误消息:


interceptor-ref?,default-action-ref?,default-class-ref?,global-results?,global-exception-
拦截器参考?,默认动作参考?,默认类参考?,全局结果?,全局异常-
mappings?,action*)”.
映射?,动作*)”。

Struts 2拦截器示例 (Struts 2 Interceptor Example)

A simple example of interceptor configuration is:

拦截器配置的一个简单示例是:

<package name="user" namespace="/" extends="struts-default">
	<interceptors>
		<interceptor name="authentication"
			class="com.journaldev.struts2.interceptors.AuthenticationInterceptor"></interceptor>
		<interceptor-stack name="authStack">
			<interceptor-ref name="authentication"></interceptor-ref>
			<interceptor-ref name="defaultStack"></interceptor-ref>
		</interceptor-stack>
	</interceptors>

	<default-interceptor-ref name="authStack"></default-interceptor-ref>
</package>

Note that defaultStack is already configured in struts-default package, that’s why we don’t need to define that in above example.

注意,defaultStack已经在struts-default包中配置了,这就是为什么我们不需要在上面的示例中定义它的原因。

Let’s create a simple application where we will use custom interceptor class to provide authentication for our application. Using interceptor will make our application loosely coupled, flexible and configurable. Our final project will look like below image.

让我们创建一个简单的应用程序,在这里我们将使用自定义拦截器类为我们的应用程序提供身份验证。 使用拦截器将使我们的应用程序松散耦合,灵活且可配置。 我们的最终项目将如下图所示。

Struts2拦截器示例项目配置文件 (Struts2 Interceptor Example Project configuration Files)

web.xml

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
	xmlns="https://java.sun.com/xml/ns/javaee"
	xsi:schemaLocation="https://java.sun.com/xml/ns/javaee https://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
	id="WebApp_ID" version="3.0">
	<display-name>Struts2InterceptorExample</display-name>

	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
	</filter>

	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
</web-app>

pom.xml

pom.xml

<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>Struts2InterceptorExample</groupId>
	<artifactId>Struts2InterceptorExample</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>war</packaging>

	<dependencies>
		<dependency>
			<groupId>org.apache.struts</groupId>
			<artifactId>struts2-core</artifactId>
			<version>2.3.15.1</version>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.1</version>
				<configuration>
					<source>1.6</source>
					<target>1.6</target>
				</configuration>
			</plugin>
			<plugin>
				<artifactId>maven-war-plugin</artifactId>
				<version>2.3</version>
				<configuration>
					<warSourceDirectory>WebContent</warSourceDirectory>
					<failOnMissingWebXml>false</failOnMissingWebXml>
				</configuration>
			</plugin>
		</plugins>
		<finalName>${project.artifactId}</finalName>
	</build>
</project>

pom.xml and web.xml configuration files are self understood.

pom.xml和web.xml配置文件是可以理解的。

struts.xml

struts.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
	"https://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
	<constant name="struts.convention.result.path" value="/"></constant>

	<package name="user" namespace="/" extends="struts-default">
		<interceptors>
			<interceptor name="authentication"
				class="com.journaldev.struts2.interceptors.AuthenticationInterceptor"></interceptor>
			<interceptor-stack name="authStack">
				<interceptor-ref name="authentication"></interceptor-ref>
				<interceptor-ref name="defaultStack"></interceptor-ref>
			</interceptor-stack>
		</interceptors>

		<default-interceptor-ref name="authStack"></default-interceptor-ref>

		<global-results>
			<result name="login" type="redirect">/home.action</result>
		</global-results>

		<action name="home">
			<interceptor-ref name="defaultStack"></interceptor-ref>
			<result>/login.jsp</result>
		</action>

		<action name="login" class="com.journaldev.struts2.actions.LoginAction">
			<interceptor-ref name="defaultStack"></interceptor-ref>
			<result name="success">/welcome.jsp</result>
			<result name="input">/login.jsp</result>
		</action>
		<action name="welcome" class="com.journaldev.struts2.actions.WelcomeAction">
			<result name="success">/welcome.jsp</result>
		</action>

	</package>

</struts>

Notice that I am declaring an interceptor authentication which is referring to class com.journaldev.struts2.interceptors.AuthenticationInterceptor.

注意,我声明了一个拦截器authentication ,该authentication是指类com.journaldev.struts2.interceptors.AuthenticationInterceptor 。

Also notice that authStack is the default interceptor-stack for the package. I am not using this stack for login.jsp because it’s used for login and at that time user will not have session to authenticate.

另请注意, authStack是该软件包的默认拦截器堆栈。 我没有将这个堆栈用于login.jsp,因为它用于登录,并且那时用户将没有会话可以进行身份​​验证。

结果页 (Result Pages)

login.jsp

login.jsp

<%@ page language="java" contentType="text/html; charset=US-ASCII"
    pageEncoding="US-ASCII"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "https://www.w3.org/TR/html4/loose.dtd">
<%-- Using Struts2 Tags in JSP --%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Login Page</title>
</head>
<body>
<h3>Welcome User, please login below</h3>
<s:form action="login">
	<s:textfield name="user" label="User Name"></s:textfield>
	<s:textfield name="password" label="Password" type="password"></s:textfield>
	<s:submit value="Login"></s:submit>
</s:form>
</body>
</html>

welcome.jsp

welcome.jsp

<%@ page language="java" contentType="text/html; charset=US-ASCII"
    pageEncoding="US-ASCII"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "https://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Welcome Page</title>
</head>
<body>
<h3>Welcome <s:property value="userName"></s:property></h3>
</body>
</html>

JSP result pages are easy to understand and nothing related to interceptors.

JSP结果页面易于理解,与拦截器无关。

型号类别 (Model Class)

User.java

User.java

package com.journaldev.struts2.models;

public class User {

	private String user;
	private String password;
	private String userName;
	public String getUser() {
		return user;
	}
	public void setUser(String user) {
		this.user = user;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	
}

A simple java bean with properties that are used in result pages. We will use this java bean in action class to hold properties.

一个简单的Java Bean,具有在结果页中使用的属性。 我们将在动作类中使用此java bean来保存属性。

定制拦截器 (Custom Interceptor)

UserAware.java

UserAware.java

package com.journaldev.struts2.interceptors;

import com.journaldev.struts2.models.User;


public interface UserAware {

	public void setUser(User user);
}

An interface similar to Struts 2 API *Aware interface, we will use it in our custom interceptor to inject values in action class. To learn more about Struts 2 API *Aware interface, please read:

与Struts 2 API * Aware接口类似的接口,我们将在自定义拦截器中使用它来将值注入操作类。 要了解有关Struts 2 API * Aware接口的更多信息,请阅读:

How to get Servlet Session, Request, Response, Context Attributes in Struts 2 Action

如何在Struts 2操作中获取Servlet会话,请求,响应,上下文属性

AuthenticationInterceptor.java

AuthenticationInterceptor.java

package com.journaldev.struts2.interceptors;

import java.util.Map;

import com.journaldev.struts2.models.User;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class AuthenticationInterceptor implements Interceptor {

	private static final long serialVersionUID = -5011962009065225959L;

	@Override
	public void destroy() {
		//release resources here
	}

	@Override
	public void init() {
		// create resources here
	}

	@Override
	public String intercept(ActionInvocation actionInvocation)
			throws Exception {
		System.out.println("inside auth interceptor");
		Map<String, Object> sessionAttributes = actionInvocation.getInvocationContext().getSession();
		
		User user = (User) sessionAttributes.get("USER");
		
		if(user == null){
			return Action.LOGIN;
		}else{
			Action action = (Action) actionInvocation.getAction();
			if(action instanceof UserAware){
				((UserAware) action).setUser(user);
			}
			return actionInvocation.invoke();
		}
	}

}

This is our custom interceptor class that is implementing com.opensymphony.xwork2.interceptor.Interceptor interface. init() and destroy() are interceptor lifecycle methods that we can implement to initialize and destroy some resources used in interceptor intercept() method.

这是实现com.opensymphony.xwork2.interceptor.Interceptor接口的自定义拦截器类。 init()和destroy()是拦截器生命周期方法,我们可以实现这些方法来初始化和销毁​​拦截器intercept()方法中使用的某些资源。

intercept() is the method invoked by ActionInvocation class, so this is where our interceptor code goes. We can get session attributes from ActionInvocation reference and use it to make sure session is valid. If we don’t find the attribute, we are returning global result “login” that will redirect user to login page. If session is valid, then we are injecting user into action class. instanceof keyword is used to make sure that action class is implementing UserAware interface. Finally we are calling ActionInvocation invoke() method that will call the next interceptor or action class in the chain.

Intercept()是ActionInvocation类调用的方法,因此这就是我们的拦截器代码所在的位置。 我们可以从ActionInvocation参考获取会话属性,并使用它来确保会话有效。 如果找不到该属性,则将返回全局结果“登录”,该结果会将用户重定向到登录页面。 如果会话有效,那么我们会将用户注入到动作类中。 instanceof关键字用于确保操作类正在实现UserAware接口。 最后,我们调用ActionInvocation invoke()方法,该方法将调用链中的下一个拦截器或操作类。

动作班 (Action Classes)

LoginAction.java

LoginAction.java

package com.journaldev.struts2.actions;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.journaldev.struts2.models.User;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class LoginAction extends ActionSupport implements SessionAware, ModelDriven<User>{

	private static final long serialVersionUID = -3369875299120377549L;

	@Override
	public String execute(){
		System.out.println("inside execute");
		if("pankaj".equals(user.getUser()) && "admin".equals(user.getPassword())){
			user.setUserName("Pankaj Kumar");
			sessionAttributes.put("USER", user);
			return SUCCESS;
		}
		return INPUT;
	}
	
	private User user = new User();
	private Map<String, Object> sessionAttributes = null;

	@Override
	public void setSession(Map<String, Object> sessionAttributes) {
		this.sessionAttributes = sessionAttributes;
	}
	
	@Override
	public User getModel() {
		return user;
	}
	
}

Notice that LoginAction is implementing SessionAware interface to get session attributes and if user is validated, then putting user attribute in session to be used in authentication interceptor for validation. Notice that LoginAction is not implementing UserAware interface.

请注意,LoginAction正在实现SessionAware接口以获取会话属性,并且如果验证了用户,则将用户属性放在会话中以在身份验证拦截器中用于验证。 请注意,LoginAction没有实现UserAware接口。

WelcomeAction.java

WelcomeAction.java

package com.journaldev.struts2.actions;

import com.journaldev.struts2.interceptors.UserAware;
import com.journaldev.struts2.models.User;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class WelcomeAction extends ActionSupport implements UserAware, ModelDriven<User> {

	private static final long serialVersionUID = 8111120314704779336L;

	@Override
	public String execute(){
		return SUCCESS;
	}
	
	private User user;
	@Override
	public void setUser(User user) {
		this.user=user;
	}
	
	public User getUser(User user){
		return this.user;
	}

	@Override
	public User getModel() {
		return this.user;
	}

}

Notice that WelcomeAction is implementing UserAware interface and our AuthenticationInterceptor is injecting it to the action class behind the scene. Notice that action class is simple and there is no code for validating the user session or to set the user bean.

注意,WelcomeAction正在实现UserAware接口,我们的AuthenticationInterceptor将其注入到幕后的action类中。 请注意,动作类很简单,没有用于验证用户会话或设置用户Bean的代码。

From above action classes code, it’s clear that if we use interceptors smartly, we can reduce a lot of code redundancy for common tasks that we need to do for multiple actions.

从上面的动作类代码中可以清楚地看出,如果我们聪明地使用拦截器,我们可以减少执行多个动作所需的常见任务的大量代码冗余。

When we execute above project, we get following response pages.

当我们执行以上项目时,我们得到以下响应页面。

If you are not logged in and you will try to invoke login.action, our authentication interceptor will forward you to login page and action class will never be invoked.

如果您尚未登录,并且尝试调用login.action,则我们的身份验证拦截器会将您转发到登录页面,并且永远不会调用action类。

That’s all for Struts 2 interceptors tutorial, it’s one of the important features of Struts 2 and you should try to use it for reusability.

这就是Struts 2拦截器教程的全部内容,这是Struts 2的重要功能之一,您应该尝试将其用于可重用性。

翻译自: https://www.journaldev.com/2210/struts-2-interceptor-example

struts2 拦截器

struts2拦截器的使用方法 struts2拦截器的使用说明文档,配置说明文档。可以看一下 立即下载

相关推荐

Struts2学习案例(拦截器)

自己写的struts2小案例,DAO是用JPA开发,包含Action,mysq等,mvc模式

struts2拦截器简单例子

自定义拦截器实现步骤: 1-1:实现Interceptor接口 1-2:继承AbstractInterceptor类 1-3:继承:MethodFilterInterceptor: 在需要配置拦截器参数的情况下使用处理拦截的方法: public String intercept(ActionInvocation invocation) throws Exception { } i

qq208617107的博客 415

struts2 拦截器实例

struts2,Interceptor struts2拦截器实例,两套实例,一套是针对单个的action配置的,另一套实例是针对全局的action配置的拦截器interceptor

Struts2拦截器

Struts2拦截器 Struts2工作原理 1、客户端发出请求 2、请求经过一系列的过滤器 包括Struts2的过滤器FilterDispatcher 3、FilterDispatcher会询问ActionMapper   3.1、当前请求不需要调用某个Action 则将该请求交给Servlet容器去处理   3.2、当前请求确定需要调用某个Action, 则将该请求的处理交给Ac...

weixin_30362801的博客 90

Struts2拦截器登录验证实例

本篇文章主要介绍了Struts2拦截器登录验证实例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

HSMS/SECS/GEM/GEM300半导体通讯协议介绍

HSMS/SECS/GEM/GEM300半导体通讯协议解决方案介绍 目录 SECS/GEM协议通讯 1 目录 2 1.介绍 3 1.1 产品概述 3 1.1.1 高扩展性 4 1.2 通讯实现 4 1.2.2多主机实现 4 1.3 当前的SEMI标准 5 1.3.1 功能跟友商对比 6 1.4 软件灵活性 7 1.5 无需学习SECS 7 1.6 自定义消息传递 8 1.7 记录收集 8 1.8 SECS Manual文档 8 1.9 产品清单 8 2 产品结构 9 2.1 控制面板 9 2.2 使用环境

semisecs 16万+

Struts2 拦截器配置和实例

拦截器只能拦截Action (1)自定义器类要实现接口Interceptor,实现相应的方法。 拦截器的init()是在服务器一启动的时候就调用的。拦截器初始化时调用。只调用一次。 destory()拦截器被销毁之前调用。 整个拦截器的核心部分是invocation.invoke()这个函数和这个函数的调用位置。 invocation.invoke()函数调用之前代码将会在Acti...

weixin_34405925的博客 111

NCCL分布式训练中ibv_reg_mr_iova2内存分配失败的3种解决方案(附详细排查流程)

本文深入探讨了NCCL分布式训练中ibv_reg_mr_iova2内存分配失败的3种解决方案,包括快速临时修复、标准系统配置和PAM模块根治方案。详细分析了错误原因,提供了完整的排查流程和性能优化建议,帮助开发者高效解决RDMA网络环境下的内存锁定问题。

nut55的博客 632

5.Struts 2拦截器(Interceptor)

任何优秀的MVC框架都会提供一些通用的操作,如请求数据的封装、类型转换、数据校验、解析上传的文件、防止表单的多次提交等。 Struts 2将它的核心功能放到拦截器中实现而不是集中在核心控制器中实现,把大部分控制器需要完成的工作按功能分开定义,每个拦截器完成一个功能,而完成这些功能的拦截器可以自由选择、灵活组合,需要哪些只需要在struts.xml指定即可,从而增加了框架的灵活性,有利于系统解耦。 拦截器的方法在Action执行之前或者执行之后自动的执行,从而将通用的操作动态地插入到了可插拔式。

相互学习 共同进步 1043

深入解析TOM模块的PWM输出与ADC触发机制:从配置到DMA数据传输

本文深入解析了TOM模块在嵌入式系统中的核心应用,详细阐述了如何配置其PWM输出功能,并实现与ADC模块的硬件触发同步。重点介绍了通过DMA机制高效传输ADC采样数据的完整流程,涵盖时钟配置、工作模式选择、引脚映射及联调实战,为电机控制、数字电源等实时系统提供了一套硬件自动化的高效解决方案。

weixin_29227585的博客 385

Unity WebGL项目如何实现画布透明,完美融入网页背景(附.jslib文件与完整配置)

本文详细解析了Unity WebGL项目实现画布透明化的技术原理与实战步骤,从.jslib文件配置到前端框架集成,帮助开发者解决默认背景色问题,实现3D内容与网页设计的无缝融合。重点介绍了透明化核心机制、常见误区及React/Vue等现代框架中的最佳实践方案。

weixin_31896061的博客 310

Struts2全局拦截器

Struts2全局拦截器

没伞的孩子就得跑的专栏 2516

《大数据最全面试题-Offer直通车》目录

做好这些不用担心试用期不通过:程序员入职新公司如何快速上手项目本人遇到大数据面试题和参考答案(超过1万字精华版)大数据面试英文自我介绍参考(万字长文)大数据运维应用场景面试题汇总及参考答案(持续更新)万字数据仓库面试题及参考答案数据仓库数据质量监控和处理方法最佳实践数据仓库建模方法万字详解Doris的3种数据模型详解和数据仓库每一层的模型选用大数据面试临阵磨枪不知看什么?看这份心理就有底了-大数据常用技术栈常见面试100道题最全Hive面试题2024年(2万字详解)Elasticsearch 面试题及参考答

大模型大数据攻城狮的专栏 2667

Struts 2 execAndWait拦截器示例

下载它– Struts2-ExecAndWait-Interceptor-Example.zip Struts 2带有一个非常有趣的“ Execute and Wait ”拦截器,名为“ execAndWait ”,它是非常方便的拦截器,用于在后台向用户显示自定义的等待页面时长时间运行的操作。 在本教程中,它显示了使用Struts 2 execAndWait拦截器的完整示例。 1.行动 ...

一名可爱的技术搬运工 228

使用 MATLAB/Simulink 进行锂电池SOC估算和等效电路建模

本文介绍了使用MATLAB/Simulink进行锂电池SOC估算与等效电路建模的方法。首先阐述了SOC估算和等效电路模型的背景及重要性,然后详细讲解了系统结构设计的主要组成部分,包括电池模块、SOC估算模块(采用卡尔曼滤波器算法)和等效电路模型等。文章重点分步说明了建模过程:从创建Simulink项目、搭建电池模块,到实现SOC估算算法(提供示例代码),构建等效电路模型(Thevenin模型示例),添加传感器模块,最后设置仿真参数。通过仿真运行分析关键指标(SOC估算误差、电压偏差等)来评估模型性能,为锂电

xiaoheshang_123的博客 270

工业激光器核心参数详解与选型实战:从理论到产线落地(五)

本文深入解析了脉冲激光加工的三大核心参数——脉宽、重复频率和脉冲能量的协同作用机制。通过公式推导和产线案例,揭示了参数设置对加工良率的关键影响:1. 脉宽决定热影响区大小,缩短脉宽可显著提升加工精度;2. 重复频率影响加工速度和热积累效应,需平衡效率与质量;3. 脉冲能量决定材料去除量,过大易导致加工缺陷。文中以ABS塑料打标、模具清洗和微孔钻孔为例,展示了参数优化如何将良率从65%提升至99%,并提供了不同应用场景的参数选型表和调试技巧,强调峰值功率比平均功率更具决定性作用。

weixin_44520581的博客 2427

Struts2 拦截器的完整示例

拦截器在 Action 执行前后记录时间,并计算出 Action 的执行时间并打印到控制台。时,该拦截器会记录请求的处理时间。

alankuo的专栏 256

基于改进YOLOv5的小目标检测 | 添加CBAM注意机制 + 更换Neck网络之BiFPN + 增加高分辨率检测头

本文针对图像中小目标难以检测的问题,提出了一种基于YOLOv5的改进模型。在主干网络中,加入CBAM注意力模块增强网络特征提取能力;在颈部网络部分,使用BiFPN结构替换PANet结构,强化底层特征利用;在检测头部分,增加高分辨率检测头,改善对于微小目标的检测能力。本文算法在无人机数据集VisDrone2019数据集上进行了多次对比实验,结果表明本文算法可以有效地检测小目标。🌈

小哥谈 2941

Struts2拦截器简单示例

拦截器(Interceptor )是Struts 2 的核心组成部分。很多功能(Feature )都是构建在拦截器基础之上的,例如文件的上传和下载、国际化、转换器和数据校验等,Struts 2 利用内建的拦截器,完成了框架内的大部分操作。 在Struts 2 文档中对拦截器的解

yinshuiy的专栏 1623

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

Struts 2拦截器堆栈示例

通常,同一组拦截器可能适用于不同的动作类,例如, <package name="default" namespace="/" extends="struts-default"> <action name="checkInAction" class="com.mkyong.common.action.CheckInAction" > <inter...

一名可爱的技术搬运工 157

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

一个Struts2 拦截器实现参数校验的代码示例

结果码,显示输入错误页面,并在页面上显示错误信息。如果校验通过,则继续执行。之前对用户名和密码进行了校验。如果校验不通过,会返回。方法,并根据结果显示相应的页面。在这个示例中,自定义拦截器。假设我们有一个用户登录的。

alankuo的专栏 260

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

struts2 拦截器_Struts2令牌拦截器示例

struts2 拦截器Struts 2 token interceptor can be used to handle multiple form submission problem. While designing web application, sometimes we have to make sure that double form submission is treated as ...

从零开始的教程世界 453
上一篇: 二叉树层级遍历_二叉树中的层级顺序遍历
下一篇: matlab分析xml文件_修改Java中的XML文件(DOM分析器)
cunchi4221
博客等级 码龄11年 643粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值