Struts2 开发程序的基本步骤
来源:互联网 发布:切削速度的编程 编辑:程序博客网 时间:2024/05/16 09:42
使用Struts2开发程序的基本步骤:
1.加载Struts2类库
2.配置web.xmlwen文件
3.开发视图层页面
4.开发控制层Action
5.配置Struts.xml文件
6.部署,运行项目
具体如下:
步骤1:配置web.xml文件
<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> <!-- 拦截所有的action --> <url-pattern>/*</url-pattern> </filter-mapping>
步骤2:在src下创建名称为struts.xml的配置文件
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""http://struts.apache.org/dtds/struts-2.3.dtd"><struts> <!-- 配置文件中只要添加以下配置,那么以后修改配置文件不用重启tomcat --> <constant name="struts.devMode" value="true" /> <package name="default" namespace="/" extends="struts-default"> <!-- 第一个action的例子 --> <action name="helloWorld" class="cn.happy.action.HelloWorldAction"> <result name="success"> index.jsp </result> </action> <!-- 登陆的action --> </package> <!-- Add packages here --></struts>
步骤3:编写HelloWorldAction
package cn.happy.action;import com.opensymphony.xwork2.Action;public class HelloWorldAction implements Action{private String name ;private String message;public String execute() throws Exception {setMessage("Hello"+getName());return "success";}}
步骤4:创建index.jsp页面
<div><h1><!--显示Struts Action中message的属性内容--><s:property value="message"/></h1></div><div><form action="helloWorld.action" method="post"> 请输入您的姓名: <input name="name" type="text" /><input type="submit" value="提交" /></form></div>
步骤5:通过浏览器访问
点击提交后结果
struts配置文件说明
<!-- 配置文件中只要添加以下配置,那么以后修改配置文件不用重启tomcat -->
<constant name="struts.devMode" value="true" />
一个警告的解决
问题描述:No configuration found for the specified action: 'login.action' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
解析:<s:form action="Login" method="post" namespace="/"> or <s:form action="/Login" method="post" >
阅读全文
0 0
- 使用Struts2开发程序的基本步骤
- 使用Struts2开发程序的基本步骤
- Struts2 开发程序的基本步骤
- Struts2开发基本步骤
- 开发Struts2应用程序-基本步骤
- 使用Struts2基本开发步骤
- 习题1.6程序开发的基本步骤
- 1.6程序开发的基本步骤是什么?
- 程序开发的基本步骤是什么?
- 【struts2】struts2的开发步骤
- Struts2的开发步骤
- Django程序开发基本步骤
- Windows程序开发的基本步骤(导入自原博客)
- 开发wxPython程序必须具备的五个基本步骤
- [Struts]Struts2的开发步骤
- Struts2 应用的开发步骤
- Struts2应用的开发步骤
- Struts2的开发步骤,简单明了
- 高频交易软硬件是怎么架构的
- 欢迎使用CSDN-markdown编辑器
- 关于在配置JDK系统变量时出现的问题的解决方案
- C语言实现一般线性表的链式存储
- Arduino 单片机之 ESP8266模块使用
- Struts2 开发程序的基本步骤
- 关于sublime text 3在使用virtualenv插件出现cancel build失效的问题
- 辗转相除法求最大公约数
- structs2
- 2017.10.21总结
- poj-1007 DNA sorting
- LQB-2
- Java中ArrayList和LinkedList区别
- HDU 1875:畅通工程再续