在这里,我们将给大家分享关于Discord.jsv12MessageReactionAdd的知识,同时也会涉及到如何更有效地ActionError,ActionMessage推荐、Actionerro
在这里,我们将给大家分享关于Discord.js v12 MessageReactionAdd的知识,同时也会涉及到如何更有效地ActionError,ActionMessage推荐、Actionerror和Actionmessage标签的用法、ActionScript Worker Message Passing is Slow(ActionScript 线程间通信速度的提升建议 )、addActionError addFieldErrot addActionMessage 的区别的内容。
本文目录一览:- Discord.js v12 MessageReactionAdd
- ActionError,ActionMessage推荐
- Actionerror和Actionmessage标签的用法
- ActionScript Worker Message Passing is Slow(ActionScript 线程间通信速度的提升建议 )
- addActionError addFieldErrot addActionMessage 的区别
Discord.js v12 MessageReactionAdd
使用user
对象来解析成员:
client.on('messageReactionAdd',async (reaction,user) => {
if (reaction.message.partial) await reaction.message.fetch();
if (reaction.message.id === '755695010657206323') {
switch (reaction.emoji.id) {
case '753885482298900510':
const member = await reaction.message.guild.members.fetch(user.id);
member.roles.add('ROLE_ID');
break;
}
}
});
ActionError,ActionMessage推荐
尽管Struts框架供给了管用的失常处理机制,但不能保证处理所有的讹谬,这时Struts框架会把讹谬抛给Web容器,在默认情形下Web容器会向用户博览器直接归来原始消息。万一想避免直接让用户看到这些原始消息,能够在web.xml中搭配<error-page>元素,以下代码演示了如何避免用户看到HTTP 404、HTTP 500讹谬和Exception失常。
web.xml
Java代码
<error-page><error-code>404</error-code><location>/exception/error404.jsp</location></error-page><error-page><error-code>500</error-code><location>/exception/error500.jsp</location></error-page><error-page><exception-type>java.lang.Exception</exception-type><location>/exception/default.jsp</location></error-page>
当WEB容器捉拿到exception-type或error-code指定的讹谬时将跳到由location指定的版面。
问题:当form bean 为动态bean时,在action中无法对formbean数据举行检讨,因为formbean未曾翔实告终类。action中无法引用ActionError/ActionErrors/ActionMessage/ActionMessages:
有时候你必需向用户供给相干处理消息,包括表单检讨时觉察讹谬等。
1. 相干类推荐:
ActionMessage:用于保留一个与资源束对应的提醒消息。重要构造函数如:
ActionMessage(String message);
ActionMessage(String message,paramater)。
ActionMessages:用于保留多个ActionMessage。并在html:errors 和html:messages中起作用。
重要构造函数:
ActionMessages().
重要措施是add(String property,ActionMessage message)
ActionMessages有一个HashMap种类messages保留多个ActionMessage对象,每个ActionMessage对象都有单一的一个property标识。这个property能够是自定义的任意字符串,也能够由org.apache.struts.action.ActionMessages.GLOBAL_MESSAGE指定
html:messages/html:errors利用property属性拜会某个资源
ActionErrors:用于保留一个与资源束对应的讹谬消息。用法跟ActionMessages差不多。
ActionError不同意利用。
2. 版本:
struts1.1管用ActionErrors报告讹谬,用ActionMessages供给消息。
在struts1.2中利用ActionMessages供给消息和讹谬,不同意利用ActionError
struts1.3中曾经未曾ActionError类了。
3. AtionErrors和ActionMessages的差异
1. ActionErrors是ActionMessages的一个子类,功能几乎雷同,不同点在于标签<html:errors/>和<html:messages>的利用上的差异。
html:errors指定了footer和header属性。默认值为errors.header和errors.footer,必需时能够自己指定。万一资源属性文件搭配了errors.header和errors.footer,则任何时候利用html:errors时开始和结尾都是这两个属性对应的资源消息。
而html:message默认情形下未曾errors.header和errors.footer值,当然能够自己指定。
2.html:errors能够依据property属性指定揭示一个讹谬消息。html:messages有一个必添项id。html:messages不能直接揭示消息,它将选出的消息纳入一个用id标识的Iterator对象里,然后在用ben:write或JSTLc:out标签揭示每个消息.例如:
Java代码
<html:messagesmessage="true"id="msg"><c:outvalue="${msg}"/><br/></html:messages>
3cf.cfeits.com. 翔实的一个例子:
接受输入版面input.jsp:
Java代码
<html:formaction="/errormessage/input">phoneNumber:<html:textproperty="phoneNumber"/><html:errorsproperty="<%=org.apache.struts.action.ActionMessages.GLOBAL_MESSAGE%>"/><br/><html:submit/><html:cancel/></html:form>
struts-config.xml:
Java代码
<form-beans><form-beanname="inputForm"type="cn.rolia.struts.form.errorexception.InputForm"/></form-beans><action-mappings><actionattribute="inputForm"input="/errormessage/input.jsp"name="inputForm"path="/errormessage/input"scope="request"type="com.yourcompany.struts.action.errormessage.InputAction"validate="false"><forwardname="success"path="/errormessage/success.jsp"/></action></action-mappings>
InputAction.java:
Java代码
publicActionForwardexecute(ActionMappingmappingwww.ria38.com,ActionFormform,HttpServletRequestrequest,HttpServletResponseresponse){cn.rolia.struts.form.errorexception.InputForminputForm=(cn.rolia.struts.form.errorexception.InputForm)form;//TODOAuto-generatedmethodstubStringphoneNumber=inputForm.getPhoneNumber();if(phoneNumber.length()<4){ActionErrorsmessages=newActionErrors();messages.add(org.apache.struts.action.ActionMessages.GLOBAL_MESSAGE,newActionMessage("error.errormessage.input"));this.saveErrors(request,messages);returnmapping.getInputForward();}returnmapping.findForward("success");}
解说:用户输入手机号码,版面跳转到InputAction扼制层举行处理,若输入数据小于4,则创立一个ActionMessage类存储相干讹谬消息。然后再创立ActionErrors类将此ActionMessage纳入ActionErrors。再调用Action的saveErrors措施将此ActionErrors保留的request范围里,然后归来input.jsp版面要求重新输入并用html:errors提醒讹谬消息。
4. Action包括saveErrors()措施和saveMessages()措施。万一创立的ActionErrors则该当调用saveErrors(),若创立的是ActionMessages则该当调用saveMessages()措施。
saveErrors ()接收ActionMessages而不是ActionErrors;同时将其保留在request中并用一个由org.apache.struts.Globals.ERROR_KEY指定的常量”org.apache.struts.Globals.ERROR_KEY”标识这个ActionMessages,便于html:errors查找。saveMessages()措施接收ActionMessages同时将其保留在request中并用一个由org.apache.struts.Globals.MESSAGE_KEY指定的常量”org.apache.struts.Globals.MESSAGE_KEY”标识这个ActionMessages,进而让html:messages从常量Globals.ERROR_KEY中遍历获取消息。能够将其属性message设置为true,那么它将从常量Globals.MESSAGE_KEY中遍历获取消息。
5. 默认情形下html:messages从
万一你想将消息保留在session里而不是request,struts1.2供给了
struts1.1 未曾的saveMessages(HttpSession session, ActionMessagesmessages)措施和saveErrors(javax.servlet.http.HttpSession session,ActionMessages errors)措施。
InputAction.java:
Java代码
publicActionForwardexecute(ActionMappingmapping,ActionFormform,HttpServletRequestrequest,HttpServletResponseresponse){cn.rolia.struts.form.errorexception.InputForminputForm=(cn.rolia.struts.form.errorexception.InputForm)form;//TODOAuto-generatedmethodstubStringphoneNumber=inputForm.getPhoneNumber();if(phoneNumber.length()<4){ActionErrorsmessages=newActionErrors();messages.add(org.apache.struts.action.ActionMessages.GLOBAL_MESSAGE,newActionMessage("error.errormessage.input"));this.saveErrors(request.getSession(true),messages);returnmapping.getInputForward();}returnmapping.findForward("success");}
String temp = "Text here"; String s = new String (temp);
Actionerror和Actionmessage标签的用法
Actionerror和Actionmessage标签的用法:
这两个标签的使用,在网上挺多答案的可是都不是我想要知道的那种答案。这一次我通过自己努力的尝试暂且知道了这两个标签的的用途拿出来和大家分享下。
这两个标签的作用是一样的都是我们在前台页面传送信息到后台时在前台提示消息他们的唯一不同点就是他们Action实例的用不同方法
的返回值;
Actionerror使用的是getActionErrors()这个方法的返回值
Actionmessage使用的是getActionmessage()这个方法的返回值
那么这两个标签到底怎么使用用在什么地方我在这里给大家做个例子吧!这样才能更好的说明问题。
我使用的环境是eclipse+tomcat的开发环境
这是我课程例子,就用这个吧!
struts.xml文件配置
<actionname="3-14,15actionerror">
<result name="success">/3-14,15actionerror.jsp</result>
</action>
测试Action类:
package action;
import com.opensymphony.xwork2.ActionSupport;
public class ActionErrorTag extends ActionSupport {
//定义两个参数接收前台提交数据
private int operand1;
private int operand2;
public int getOperand1() {
return operand1;
}
public void setOperand1(int operand1) {
this.operand1 = operand1;
}
public int getOperand2() {
return operand2;
}
public void setOperand2(int operand2) {
this.operand2 = operand2;
}
public String execute() {
if(getOperand1()==123456){
addActionMessage("账号验证成功");
if(getOperand2()==123456){
addActionMessage("密码验证成功");
}else{
addActionError("密码验证失败!");
}
}else{
addActionError("账号验证失败!");
}
return SUCCESS;
}
}
前台页面实例代码:
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!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=GBK">
<title>
struts2 actionerror标签示例
</title>
</head>
<body>
<h3>
<!-- JSP页面中使用<s:actionerrror/>和<s:actionmessage/>>来输出ActionError和ActionMessage信息。下面是该JSP页面中使用这两个标签的示例代码:-->
<!-- 输出getActionError()方法返回值 -->
<s:actionerror/>
<!-- 输出getActionMessage()方法返回值 -->
<s:actionmessage />
<<s:form action="/3-14,15actionerror.action">
<s:textfield name="operand1" label="操作数1"/>
<s:textfield name="operand2" label="操作数2"/>
<s:submit value="代数和"/>
</s:form>
<br>
<hr size="3" color="blue">
</body>
</html>
如果那里说错了希望大家指点下 我是刚学习的哈!谢谢
ActionScript Worker Message Passing is Slow(ActionScript 线程间通信速度的提升建议 )
Originaly From: http://jacksondunstan.com/articles/2390
Since Flash Player 11.4 was released we have finally been given the ability to run multiple threads of AS3 code to take advantage of modern multi-core cpus. However,when we start writing this multi-threaded code we immediately run into the requirement to coordinate the threads by passing messages between them. As it turns out,this is quite slow in AS3. Read on for the performance analysis.
The following test app performs a very simple task in two ways. The main thread passes a series of integers to a worker thread and the worker thread adds those integers together to compute their sum. Two ways of accomplishing this task are used. The first way passes 1000 individual messages to the worker thread,each with an integer to add. A final message is passed to tell the worker to pass the sum back to the main thread and clear for the next test. The second way of computing the sum creates aByteArray
with the shareable
flag set to true
. ThisByteArray
is then filled with all of the integers to sum and sent to the worker thread. The worker thread extracts these integers,adds them together,and passes a message back with the sum.
These two ways have been designed such that one passes a lot of messages and the other only passes one. Check out the source code for details.
Run the test
I ran this test in the following environment:
- Release version of Flash Player 11.8.800.170
- 2.3 Ghz Intel Core i7
- Mac OS X 10.8.5
- ASC 2.0.0 build 353981 (
-debug=false -verbose-stacktraces=false -inline -optimize=true
)
And here are the results I got:
The ByteArray
version is clearly leaps and bounds faster than the direct version that passes individual messages. In this test environment at least,each message is taking 0.02359 milliseconds. A mere 50 messages would eat up a whole millisecond of this relatively-fast cpu,probably far too much for a complex game that’s otherwise busy with 3D graphics,physics,and so forth. If you can,it’s much quicker to bundle up these messages into aByteArray
marked shareable
and send them all over at once.
addActionError addFieldErrot addActionMessage 的区别
一、addActionError("错误内容"):Action级别的错误消息
this.addActionError("错误信息1");
this.addActionError("错误信息2");
显示消息的标签是:<s:actionerror />显示全部的 Action级别的错误消息,可以加CSS
二、addFieldError("字段名","错误信息")给一个字段(属性)添加错误消息
this.addFieldError("pwd", "错误信息1");
this.addFieldError("pwd", "错误信息2");
显示消息的方法1:标签是:<s:fielderror />显示全部的错误消息;
显示消息的方法2:
<s:fielderror>
<s:param>field1 </s:param> 显示指定的 field1字段的 错误消息
<s:param>field2 </s:param> 显示指定的 field2字段的 错误消息
</s:fielderror>
显示消息的方法3:如果什么都不写,则默认显示在相应字段上方
三、addActionMessage("相关信息")
需要在action中重写父类的validate方法,对参数进行校验,如果校验失败。则直接写错误信息
this.addActionMessage("信息1");
this.addActionMessage("信息2");
显示消息的标签是:<s2:actionmessage/>可以显示全部的消息
注:1、在添加第一个信息之前加上this.clearErrorsAndMessages();用来清空之前加载的错误信息
2、如果<head></head>之间加上<s:head/>,<s:actionerror />和<s:fielderror />会自动加上CSS
<s:actionmessage/>则不会加载.
关于Discord.js v12 MessageReactionAdd的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于ActionError,ActionMessage推荐、Actionerror和Actionmessage标签的用法、ActionScript Worker Message Passing is Slow(ActionScript 线程间通信速度的提升建议 )、addActionError addFieldErrot addActionMessage 的区别的相关知识,请在本站寻找。
本文标签: