Struts开发框架实例 及注意事项
2017-06-04 12:44
477 查看
在刚开始写第一个框架案例时:
一.注意各个类型的文件的存储位置:
二.特别注意web.xml和struts.xml的文件配置不能出错,下面是我配置的两个代码片:
web.xml:<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <session-config> <session-timeout> 30 </session-timeout> </session-config> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <filter> <filter-name> struts2 </filter-name> <filter-class> org.apache.struts2.dispatcher.FilterDispatcher </filter-class> </filter> <filter> <filter-name> struts2-cleanup </filter-name> <filter-class> org.apache.struts2.dispatcher.ActionContextCleanUp </filter-class> </filter> <filter-mapping> <filter-name> struts2 </filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name> struts2-cleanup </filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>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> <constant name="struts.ui.theme" value="simple" /> <package name="test" extends="struts-default"> <action name="sayWelcome" class="myActions.sayHello"> <result name="success">/welcome.jsp</result> <result name="input">/index.jsp</result> </action> </package> </struts>另外的几个.jsp文件和.java文件如下 index.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@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=UTF-8"> <title>第一个Struts 2应用</title> </head> <body> <s:form action="sayWelcome"> 请输入用户名:<s:textfield name="username" size="20"/> <s:submit value="确定"/> <s:reset value="重写"/> </s:form> <s:if test="hasFieldErrors()"> <s:fielderror/> </s:if> </body> </html>welcome.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!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=UTF-8"> <title>登录成功</title> </head> <body> ${username} ,欢迎光临! </body> </html>sayHello.java:
package myActions; import com.opensymphony.xwork2.ActionSupport; public class sayHello extends ActionSupport { private String username; String getUsername(){return username;} public void setUsername(String username){this.username=username;} public String execute() throws Exception{ return SUCCESS; } public void validate(){ if(username==null||username.trim().length()<5){ addFieldError("username","用户名错误!"); } } }
相关文章推荐
- 实施软件平台与框架开发的注意事项
- 关于开发框架的注意事项
- 《连载 | 物联网框架ServerSuperIO教程》- 8.单例通讯模式开发及注意事项
- 实施软件平台与框架开发的注意事项
- 《连载 | 物联网框架ServerSuperIO教程》- 8.单例通讯模式开发及注意事项
- 实施软件平台与框架开发的注意事项
- 《连载 | 物联网框架ServerSuperIO教程》- 6.并发通讯模式开发及注意事项
- 《连载 | 物联网框架ServerSuperIO教程》- 6.并发通讯模式开发及注意事项
- 一个掌握Struts企业级Web开发框架的实例 (转载)
- MyBatis框架的开发流程及注意事项
- 实施软件平台与框架开发的注意事项
- 《连载 | 物联网框架ServerSuperIO教程》- 5.轮询通讯模式开发及注意事项。附:网友制作的类库说明(CHM)
- TP框架开发的站点使用phpdoctor生成文档注意事项
- 一个掌握Struts企业级Web开发框架的实例
- 一个掌握Struts企业级Web开发框架的实例
- 实施软件平台与框架开发的注意事项 推荐
- 一个掌握Struts企业级Web开发框架的实例【转载】
- 微信小程序2--框架分析(开发注意事项)
- 微信小程序 canvas开发实例及注意事项
- 《连载 | 物联网框架ServerSuperIO教程》- 7.自控通讯模式开发及注意事项