java action层是什么意思 java action类的作用
大家好,今天给各位分享java action层是什么意思的一些知识,其中也会对java action类的作用进行解释,文章篇幅可能偏长,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在就马上开始吧!
java action类的作用
public interface Actionextends ActionListener
Action接口提供 ActionListener接口的一个有用扩展,以便若干控件访问相同的功能。
除了 ActionListener接口定义的 actionPerformed
方法之外,此接口还允许应用程序在一个位置定义:
描述函数的一个或多个文本字符串。这些字符串可用于显示按钮的立体文本、在菜单项中设置文本等等。
描述函数的一个或多个图标。这些图标可用于菜单控件中的图像,或者用于更复杂用户界面中的合成项。
功能的启用/禁用状态。应用程序可以禁用实现此接口的函数,而不必分别禁用菜单项和工具栏按钮。所有为侦听状态更改而注册为侦听器的组件都将禁止为该项生成事件,并相应地修改显示。
可以将此接口添加到现有类中,或者用它创建一个适配器(通常通过子类化 AbstractAction来实现)。然后可以将
Action对象添加到多个可感知 Action的容器中,并连接到可容纳
Action的组件。然后可以通过调用 Action对象的 setEnabled
方法立刻激活或取消激活 GUI控件。
注意,Action实现在存储方面的开销比典型的 ActionListener
要高,但后者不具有集中控制功能和广播属性更改的优点。因此,应该注意只在需要这些优点的地方使用 Action,在别处使用
ActionListener即可。
支持 Action的 Swing组件
许多 Swing的组件都具有 Action属性。在组件上设置 Action
时,会发生以下几种情况:
Action被作为 ActionListener添加到组件。
组件配置自身的某些属性以匹配 Action。
组件在 Action上安装 PropertyChangeListener,这样组件可更改其属性以反映 Action属性中的更改。
java中dao层和service层的区别是什么
dao层:dao层叫数据访问层,全称为data access object,属于一种比较底层,比较基础的操作,具体到对于某个表、某个实体的增删改查
service层:service层叫服务层,被称为服务,肯定是相比之下比较高层次的一层结构,相当于将几种操作封装起来。
至于为什么service层要使用接口来定义有以下几点好处:
在java中接口是多继承的,而类是单继承的,如果你需要一个类实现多个service,你用接口可以实现,用类定义service就没那么灵活
要提供不同的数据库的服务时,我们只需要面对接口用不同的类实现即可,而不用重复地定义类
编程规范问题,接口化的编程为的就是将实现封装起来,然调用者只关心接口不关心实现,也就是“高内聚,低耦合”的思想。
扩展资料:
Java Web,是用Java技术来解决相关web互联网领域的技术总和。web包括:web服务器和web客户端两部分。Java在客户端的应用有java applet,不过使用得很少,Java在服务器端的应用非常的丰富,比如Servlet,JSP和第三方框架等等。Java技术对Web领域的发展注入了强大的动力。
参考资料:Web Service百度百科数据访问层百度百科
Java中的actionlistener是什么意思,有什么作用,详细点为好!
actionlistener字面上理解就是动作监听器。
它是一个接口,在实现此接口的类中,你可以给需要关注其动作的组件(如Button)添加监听器(addActionListener(this);),之后在事件处理方法(public void actionPerformed(ActionEvent event){})中,对每个事件进行不同处理。
给你个例子吧,是我自己写的一个记事本:
import java.io.*;
import java.awt.event.*;
import javax.swing.*;
public class MainClass extends JFrame implements ActionListener{
int width= 500,height= 400;
JPanel panel;
JMenuBar bar;
JMenu fileMenu,editMenu,helpMenu;
JMenuItem打开O,新建N,保存S,另存A,剪切T,复制C,粘贴P,关于A;
JTextArea textArea= null;
File tempFile= null;
public MainClass(){//构造方法
setTitle("TextEdit");
setSize(width,height);
panel=(JPanel)getContentPane();
bar= new JMenuBar();
fileMenu= new JMenu("文件F");
fileMenu.setMnemonic('F');
editMenu= new JMenu("编辑E");
editMenu.setMnemonic('E');
helpMenu= new JMenu("帮助H");
helpMenu.setMnemonic('H');
打开O= new JMenuItem("打开O");
打开O.setMnemonic('O');
新建N= new JMenuItem("新建N");
新建N.setMnemonic('N');
保存S= new JMenuItem("保存S");
保存S.setMnemonic('S');
另存A= new JMenuItem("另存A");
另存A.setMnemonic('A');
剪切T= new JMenuItem("剪切C");
剪切T.setMnemonic('t');
复制C= new JMenuItem("复制C");
复制C.setMnemonic('C');
粘贴P= new JMenuItem("粘贴P");
粘贴P.setMnemonic('P');
关于A= new JMenuItem("关于A");
关于A.setMnemonic('A');
fileMenu.add(打开O);
fileMenu.add(新建N);
fileMenu.add(保存S);
fileMenu.add(另存A);
bar.add(fileMenu);
editMenu.add(剪切T);
editMenu.add(复制C);
editMenu.add(粘贴P);
bar.add(editMenu);
helpMenu.add(关于A);
bar.add(helpMenu);
textArea= new JTextArea();
panel.add("North",bar);
panel.add("Center", textArea);
打开O.addActionListener(this);
新建N.addActionListener(this);
保存S.addActionListener(this);
另存A.addActionListener(this);
剪切T.addActionListener(this);
复制C.addActionListener(this);
粘贴P.addActionListener(this);
关于A.addActionListener(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public void actionPerformed(ActionEvent event){//处理事件
if(event.getSource()==打开O){//处理打开
JFileChooser jfc= new JFileChooser();
jfc.showOpenDialog(panel);
tempFile= jfc.getSelectedFile();
FileReader fis;
try{
fis= new FileReader(tempFile);
textArea.read(fis,null);
textArea.setEditable(true);
}catch(Exception ex){ex.printStackTrace();}
}
if(event.getSource()==新建N){//处理新建
textArea.setEditable(true);
textArea.setText(null);
}
if(event.getSource()==保存S){//处理保存
if(tempFile== null){
JFileChooser jfc= new JFileChooser();
jfc.showSaveDialog(panel);
tempFile= jfc.getSelectedFile();
try{
FileWriter fos= new FileWriter(tempFile);
textArea.write(fos);
}catch(Exception ex){ex.printStackTrace();}
}
else{
try{
FileWriter fos= new FileWriter(tempFile);
textArea.write(fos);
}catch(Exception ex){ex.printStackTrace();}
}
}
if(event.getSource()==另存A){//处理另存
JFileChooser jfc= new JFileChooser();
jfc.showSaveDialog(panel);
tempFile= jfc.getSelectedFile();
try{
FileWriter fos= new FileWriter(tempFile);
textArea.write(fos);
}catch(Exception ex){ex.printStackTrace();}
}
if(event.getSource()==剪切T){//处理剪切
textArea.cut();
}
if(event.getSource()==复制C){//处理复制
textArea.copy();
}
if(event.getSource()==粘贴P){//处理粘贴
textArea.paste();
}
if(event.getSource()==关于A){//处理关于
textArea.setText("Manifest-Version: 1.0\n"+
"Created-By: Libra_JL\n"+
"QQ: 254791521\n");
textArea.setEditable(false);
panel.validate();
validate();
}
}
public static void main(String []args){//主函数
new MainClass();
}
}
@Action(value="/login"在java语句中是什么意思
struts中采用注解配置Action
需要导入struts2-convention-plugin的jar包
Action
省略getters和setters
@ParentPackage("xystruts-default")
@Namespace("/login")
publicclassLoginActionextendsBaseAction
{
privateStringverifyCode;
@Action(value="login",results={@Result(location="/pages/main.jsp"),@Result(name="login",location="/pages/login.jsp")})
publicStringlogin()
{
StringsysVerifyCode=(String)getSession().get("verifyCode");
if(StringHelper.isEmpty(verifyCode)||!sysVerifyCode.equalsIgnoreCase(verifyCode))
{
addActionError("验证码错误");
return"login";
}
return"success";
}
@Action(value="logout",results={@Result(location="/pages/login.jsp")})
publicStringlogout()
{
Mapsession=getSession();
if(session!=null)
session.clear();
return"success";
}
}
JSP
<formaction="login/login.action"></form>
<arel="external nofollow" href="login/logout.action">登出</a>
其中Result注解中name属性为空,表示默认为"success"
常用注解如下
Namespace:指定命名空间
ParentPackage:指定父包
Result:提供了Action结果的映射(一个结果的映射)
Results:Result注解列表
ResultPath:指定结果页面的基路径
Action:指定Action的访问URL
Actions:Action注解列表
ExceptionMapping:指定异常映射(映射一个声明异常)
ExceptionMappings:一级声明异常的数组
InterceptorRef:拦截器引用
InterceptorRefs:拦截器引用组
好了,本文到此结束,如果可以帮助到大家,还望关注本站哦!