java里action什么意思?@Action(value="login"在java语句中是什么意思
大家好,感谢邀请,今天来为大家分享一下java里action什么意思的问题,以及和@Action(value="/login"在java语句中是什么意思的一些困惑,大家要是还不太明白的话,也没有关系,因为接下来将为大家分享,希望可以帮助到大家,解决大家的问题,下面就开始吧!
Action在编程中的意思是什么
肯定不是FORM表单那么简单了!如果楼主看JAVA相关资料,那一般指的就是STRUTS2中的ACTION,它在资源访问处理上是以后缀呈现的。比如qq.com/login.action,STRUTS1是qq.com/login.do,当然啦,这也没有什么,一样可以在配置文件中把后缀改成其它的!
如果是类Action,那就更没什么了。很多程序员写STRUTS方法的时候,都在方法后加ACTION,比如:loginAction(){}。。
@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:拦截器引用组
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();
}
}
关于java里action什么意思的内容到此结束,希望对大家有所帮助。