My first Struct experience
来源:互联网 发布:南京高新区网络问政 编辑:程序博客网 时间:2024/05/17 19:57
My first Struct experience
标签(空格分隔): struct
- My first Struct experience
- 使用struct步骤
- 第一个struct程序
- 3种配置文件的优先级
- 使用struct步骤
使用struct步骤
1.引入struct架包
2.配置web.xml,设置struct过滤器
<filter> <filter-name>Structs2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>Structs2<filter-name><url-pattern>/*</url-pattern> </filter-mapping>
3.创建structs.xml 并引入dtd约束
解压struts2-core-2.3.1.jar,找到struts-2.3.dtd,打开
并复制代码
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd">
粘贴到你的structs.xml文件中
第一个struct程序
struts.xml注册action
<?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><package name="loginDeal" namespace="/loginDeal" extends="struts-default"><action name="login" class="com.tang.actions.loginAction"> <result name="success">/welcome.jsp</result> <result name="false">/error.jsp</result></action></package></struts>
web.xml配置structs2
<?xml version="1.0" encoding="UTF-8"?><web-app version="3.0"><filter><filter-name>structs2</filter-name><filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class></filter><filter-mapping><filter-name>structs2</filter-name><url-pattern>/*</url-pattern></filter-mapping></web-app>
loginAction.java
package com.tang.actions;public class loginAction { private String name=null; private String password=null; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String execute(){ if("admin".equals(name)&&"admin".equals(password)){ return "success"; }else{ return "false"; } }}
login.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>My JSP 'loginTest.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> </head> <body> <center> <h1>登陆</h1><br> <form action="loginDeal/login" method="POST"> name:<input type="text" name="name" /><br> password:<input type="password" name="password"><br/> <input type="submit" value="登陆" /> </form> </center> </body></html>
对于初学者经常犯的一些错误
*structs.xml文件放错地方,应该放在src目录下面
*form表单里面的input的name要与Actiond的属性名字要一致,不然接受不到表单数据
3种配置文件的优先级
web.xml>struts.properties>struts.xml
0 0
- My first Struct experience
- my first Ah-counter experience
- My first research experience...and tips
- My first experience of using unbuntu
- first-Experience
- gdb my experience
- My remote working experience
- the first experience
- First Job Experience
- My experience of learning English
- My experience on Cairngorm Framework
- Spring Security Experience My project
- My important experience---android position
- my experience on evernote<0>
- My first
- MY FIRST
- my first
- my First
- iOS for循环创建UIButton及点击处理
- 你必须知道的bower私库
- 静态链表的基本操作
- ErrorCode:1068.Multipleprimarykeydefined
- 思想归纳
- My first Struct experience
- Android 混淆问题记录can't find superclass or interface
- Helix --未完待续
- js和SpringMvc灵活使用cookie
- 数据结构-二叉树的先序、中序、后序遍历
- 多进程和多线程的应用场景
- Java 中重写与重载的规则、区别
- android的内存管理简介
- strcpy与memcpy的区别