Intellij IDEA Struts 2 注解 示例
来源:互联网 发布:数据可视化怎么做 编辑:程序博客网 时间:2024/05/21 07:12
https://www.mkyong.com/struts2/struts-2-hello-world-annotation-example/
demo下载
http://www.mkyong.com/wp-content/uploads/2010/06/Struts2-Hello-World-Annotation-Example.zip
struts2 注解
1. 更新 pom.xml
使用 Struts 2 注解特性, 你需要下载 struts2-convention-plugin.jar.
pom.xml
<dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-core</artifactId> <version>2.1.8</version> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-convention-plugin</artifactId> <version>2.1.8</version> </dependency>
2. LoginAction
创建一个 LoginAction 继承 ActionSupport
Annotation 版本
package com.mkyong.user.action;import org.apache.struts2.convention.annotation.Namespace;import org.apache.struts2.convention.annotation.Result;import org.apache.struts2.convention.annotation.ResultPath;import com.opensymphony.xwork2.ActionSupport;@Namespace("/User")@ResultPath(value="/")@Result(name="success",location="pages/login.jsp")public class LoginAction extends ActionSupport{}
XML 等价
<package name="user" namespace="/User" extends="struts-default"> <action name="Login"> <result>pages/login.jsp</result> </action></package>
3. WelcomeUserAction
重写 the execute() 方法 并且 指定注解.
Annotation 版本
package com.mkyong.user.action;import org.apache.struts2.convention.annotation.Action;import org.apache.struts2.convention.annotation.Namespace;import org.apache.struts2.convention.annotation.Result;import org.apache.struts2.convention.annotation.ResultPath;import com.opensymphony.xwork2.ActionSupport;@Namespace("/User")@ResultPath(value="/")public class WelcomeUserAction extends ActionSupport{ private String username; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } @Action(value="Welcome", results={ @Result(name="success",location="pages/welcome_user.jsp") }) public String execute() { return SUCCESS; }}
XML 等价
<package name="user" namespace="/User" extends="struts-default"> <action name="Welcome" class="com.mkyong.user.action.WelcomeUserAction"> <result name="SUCCESS">pages/welcome_user.jsp</result> </action></package>
4. JSP 视图页面
一旦点击 submit 按钮,
普通 JSP 视图页面 接收 username 和 password,
and 跳转 去 a welcome 视图页面 。
login.jsp
<%@ page contentType="text/html; charset=UTF-8" %><%@ taglib prefix="s" uri="/struts-tags" %>Struts 2 Hello World Annotation Example
welcome_user.jsp
<%@ page contentType="text/html; charset=UTF-8" %><%@ taglib prefix="s" uri="/struts-tags" %>Struts 2 Hello World Annotation ExampleHello
5. struts.xml
不需要创建 struts.xml file, 所有的Class文件都是注解的.
6. web.xml
Just 创建 web.xml 文件 and 声明 the FilterDispatcher filter 。
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" ><web-app> <display-name>Struts 2 Web Application</display-name> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping></web-app>
7. 运行它
The LoginAction.action is changed to login.action, see “Naming Converter” above.
http://localhost:8080/Struts2Example/User/login.action
Struts 2 注解 login 界面
http://localhost:8080/Struts2Example/User/Welcome.action
Struts 2 annotation welcome screen
demo下载
http://www.mkyong.com/wp-content/uploads/2010/06/Struts2-Hello-World-Annotation-Example.zip
引用
Struts 2 convention plugin 文档
http://struts.apache.org/2.1.8/docs/convention-plugin.html
Strust 2 Hello World (XML 版本)
http://www.mkyong.com/struts2/struts-2-hello-world-example/
其他文章:
struts-2-example
https://dzone.com/tutorials/java/struts-2/struts-2-example/struts-2-annotations-example-1.html
Struts2的注解功能
http://www.cnblogs.com/wayne_wang/archive/2011/01/24/1942927.html
end
- Intellij IDEA Struts 2 注解 示例
- 首次运行 IntelliJ IDEA 示例
- idea创建struts项目示例
- intellij idea开发struts+hibernate流程
- Intellij IDEA配置Android Annotations注解框架
- Intellij IDEA配置Android Annotations注解框架
- Intellij IDEA搭建maven+注解SpringMVC框架
- IntelliJ IDEA 类代码模板注解自定义
- IntelliJ IDEA 自定义方法注解模板
- IntelliJ IDEA 中创建HelloWorld项目示例
- IntelliJ IDEA Debug调试示例一
- idea(IntelliJ IDEA 15.0.2)配置项目
- Intellij IDEA 6.0 加强了对struts的支持!
- 使用IntelliJ IDEA提示找不到struts-default文件
- Intellij idea 不能识别 @Slf4j,@Getter ,@Setter注解,编译通过
- Intellij idea 不能识别 @Slf4j,@Getter ,@Setter注解,的问题
- Intellij idea 不能识别 @Slf4j ,@Getter ,@Setter 注解
- Intellij IDEA struts2 json [指定类成员] [xml、注解]
- servlet/filter/listener/interceptor区别与联系
- MongoDB:5-MongoDB的固定集合(capped collection)
- jQuery(下)-课堂笔记
- MongoDB:6-MongoDB的聚合和管道
- OSI七层与TCP/IP五层网络架构详解
- Intellij IDEA Struts 2 注解 示例
- pbs作业调度用法
- bzoj 1212: [HNOI2004]L语言
- 第一天开博客,随便写点啥
- Linux下 环境变量/etc/profile、/etc/bashrc、~/.bashrc的区别
- Java练习题10
- web阶段总结-课堂笔记
- 设计模式【桥接模式Bridge Pattern】
- poj 3304 Segments(叉积+直线和线段相交判断)