Eclipse搭建Struts2
来源:互联网 发布:经典java编程面试题 编辑:程序博客网 时间:2024/05/22 11:51
版本2.3.20
第一步:在http://struts.apache.org/download.cgi下载Struts2的最新版
第二步:解压下载的压缩包。在struts-2.3.20-all.zip\struts-2.3.20\apps\struts2-blank.war 解压出来,把这个文件用压缩工具解压到文件夹出来,将\struts2-blank\WEB-INF\lib下的jar所有拷贝到你项目的lib下
第三步:在web.xml配置文件中,配置Struts2的核心Filter过滤器。代码如下:
<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><url-pattern>/*</url-pattern></filter-mapping>第四步:在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><constant name="struts.enable.DynamicMethodInvocation" value="false" /><constant name="struts.devMode" value="true" /><package name="default" namespace="/" extends="struts-default"><default-action-ref name="index" /><global-results><result name="error">error.jsp</result></global-results><global-exception-mappings><exception-mapping exception="java.lang.Exception"result="error" /></global-exception-mappings><action name="login" class="com.test.action.LoginAction"><result name="success">/success.jsp</result><result name="error">/index.jsp</result></action></package></struts>action主要是对红色部分的修改。成功和错误的页面设置。登陆成功跳转到success.jsp,失败跳转到index.jsp页面。
index.jsp是登陆页面。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title></title></head><body><form action="login.action" method="get"><table><tr><td>用户名:</td><td><input type="text" name="username"></td></tr><tr><td>密码:</td><td><input type="password" name="password"></td></tr><tr><td></td><td><input type="submit" value="登陆"></td></tr></table></form></body></html>action的名称和struts.xml的action名称对应。
success.jsp是登陆成功的页面。
第五步:创建处理用户请求的Action类,继承于ActionSupport类
package com.test.action;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport {private String username, password;public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public String execute() throws Exception {if (username.equals("admin") && password.equals("admin")) {return SUCCESS;}return ERROR;}}
0 0
- Eclipse搭建Struts2
- Eclipse搭建Struts2环境
- Eclipse搭建Struts2
- Eclipse搭建Struts2
- Eclipse 搭建Struts2
- Eclipse 搭建Spring Struts2
- Eclipse搭建Struts2框架
- Maven+struts2+eclipse环境搭建
- Struts2框架搭建(eclipse)
- Eclipse上struts2环境搭建
- 【Struts2】eclipse 下搭建 Struts2 开发环境
- Eclipse搭建Struts2.3.4 源码调试环境
- Eclipse中 struts2 + spring3 + mybatis3 环境搭建
- Eclipse搭建SSH(Struts2+Spring3+Hibernate3)实践
- Eclipse中 struts2 + spring3 + mybatis3 环境搭建
- Eclipse下搭建Struts2开发环境
- 【环境搭建】Eclipse EE 配置 struts2
- 在eclipse开发环境中搭建struts2
- 【hadoop】 1006-ssh免登陆
- yii 常用路径
- 【tcp网络编程】用Socket建立一个简单的文本转换服务器
- 【hadoop】 1007-如何建立网卡和MAC地址的关联
- Marvin_wu-嵌入式 - fpga-DSP领域
- Eclipse搭建Struts2
- 启动受管Server报错,自己犯了弱智问题
- http://blog.csdn.net/huanghuanghbc/article/details/9357629
- 我的技术路线小结2(2011-2014)
- java时间方面的知识点
- wgwg
- TNS-12541: TNS:no listener
- 软件项目开发团队组员跨项目组兼职案例分析
- wegwg