SSH三大框架整合配置详细步骤(1)
配置Struts2.0
3.1 基础配置
1)引入Struts必需的五个jar包。下载struts-2.1.6-all.zip解压后,struts-2.1.6\lib目录下是struts所有的相关jar包。这么多jar包并不是struts必须得,使用struts只需要把下面五个引入即可,以后用到什么jar包,再引入。放到webroot->webinf->lib下面。
² commons-logging-1.0.4.jar
² freemarker-2.3.15.jar
² Ognl-2.7.3.jar
² Struts2-core-2.1.8.jar
² xwork-core-2.1.6.jar
2)修改WEB-INF下的web.xml文件,增加struts2的配置。增加代码如下:这些配置代码对于struts2是不变的,直接复制到web.xml即可。
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<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>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
3)添加struts配置文件。
在src目录下,新建struts.xml,模版如下:
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
</struts>
好了,struts基本配置完毕,是不是很简单?
现在把工程发布到tomcat上去测试一下,在工程名字上点击右键,选择MyEclipseàAdd and Remove project Deployments,在打开的窗口里,点击Add,选择我们之前配置好的tomcat6服务器,如下图:
发布好了,启动tomcat,如果启动无异常,则说明配置成功。
注意:可能会出现struts-default.xml相关异常,根据提示引入相关jar包。我测试的时候是缺少fileupload相关jar包,于是引入了commons-fileupload-1.2.1.jar。
3.2 配置一个Action
下面开始配置一个Action吧,以用户登录为例:
1)首先在webroot下面新建一个登陆页面login.jsp,代码如下:
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>登录</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head>
<body>
<s:form name="form1" action="login.action" method="post">
<s:textfield name="username" label="username" ></s:textfield>
<s:password name="password" label="password" ></s:password>
<s:submit label="submit"></s:submit>
</s:form>
<s:actionerror/>
</body>
</html>
2)在我们已经建好的struts.xml中来配置登录的action。这里定义登录action的名字为login,配置代码如下:
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="struts2" extends="struts-default" namespace="/">
<action name="login" class="test.LoginAction">
<result name="success" type="redirect">/index.jsp</result>
<result name="input">/login.jsp</result>
<result name="error">/login.jsp</result>
</action>
</package>
</struts>
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport
{
public String username;
public String password;
public String execute()
{
if(!username.equals("admin"))
{
super.addFieldError("username", "用户名错误!");
return ERROR;
}
if(!password.equals("001"))
{
super.addFieldError("password", "密码错误!");
return ERROR;
}
return SUCCESS;
}
public void validate()
{
if(username==null||username.length()==0)
{
super.addActionError("用户名不能为空");
}
if(password==null||password.length()==0)
{
super.addActionError("密码不能为空");
}
}
}
4)好了,一个Action就创建完成了,重启tomcat测试一下吧。如果第一次使用struts,你可能你明白上面的代码,以后慢慢学习即可,现在先来看一下效果吧。
打开登录页面http://localhost:8080/工程名字/login,输入正确或错误的用户名和密码,看看有什么提示。
SSH三大框架整合配置详细步骤(1)的更多相关文章
- SSH三大框架整合配置详细步骤(3)
5 配置Spring2.5 5.1 基础配置 1) 导入spring包.下载spring-framework-2.5.6并解压后,在spring-framework-2.5.6" ...
- SSH三大框架整合配置详细步骤(2)
4 配置Hibernate Hibernate MySql连接配置 在Hibernate中,可以配置很多种数据库,例如MySql.Sql Server和Oracle,Hibernate MySql连接 ...
- SSH三大框架整合配置详解
首先,三大框架整合,肯定是要导入相当多的jar包,这是不容置疑的! 这里就不一一列举了,直接截图吧: (1) 基于配置文件的整合: 第一步:我们需要在we ...
- Maven SSH三大框架整合的加载流程
<Maven精品教程视频\day02视频\03ssh配置文件加载过程.avi;> 此课程中讲 SSH三大框架整合的加载流程,还可以,初步接触的朋友可以听一听. < \day02视频\ ...
- SSH三大框架整合案例
SSH三大框架的整合 SSH三个框架的知识点 一.Hibernate框架 1. Hibernate的核心配置文件 1.1 数据库信息.连接池配置 1.2 Hibernate信息 1.3 映射配置 ...
- JavaWeb_(SSH)三大框架整合struts+hibernate+spring_Demo
三大框架整合 一.SSH导包 二.书写Spring 三.书写Struts 四.整合Spring与Struts 五.书写(与整合)Hibernate.引入c3p0连接池并使用hibernate模板 六. ...
- 关于ssh三大框架整合的碎碎念
三大框架整合,无非就是一个导jar包,修改配置文件的过程.完了就没事了. 还是有很多细节性的问题 比如在spring中写applicationContext.xml文件时不提示: 解决方法如下: 如果 ...
- 吴裕雄--天生自然JAVA SPRING框架开发学习笔记:SSM(Spring+Spring MVC+MyBatis)框架整合搭建详细步骤
因为 Spring MVC 是 Spring 框架中的一个子模块,所以 Spring 与 SpringMVC 之间不存在整合的问题.实际上,SSM 框架的整合只涉及 Spring 与 MyBatis ...
- SSH三大框架整合步骤
Struts2:需要整合的第一个框架: 1.创建一个动态web项目 2.导入struts2必须的jar 放到 lib目录下 ,再 build path 添加web工程中 3.配置struts2的核心配 ...
随机推荐
- Java中线程的使用
多线程的创建及启动 一.继承Thread类创建线程子类 1.在这子类中重写run方法,在run方法内写线程任务代码 2.创建该子类实例,即是创建了一个线程实例 3.调用该实例的start方法来启动该线 ...
- 关于Hibernate中No row with the given identifier exists问题的原因及解决
今天遇到一个bug,截图如下 有两张表,table1和table2.产生此问题的原因就是table1里做了关联<one-to-one>或者<many-to-one unique=&q ...
- HDU 4436 str2int
str2int Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on HDU. Original ID: 4 ...
- java常见问题集锦
Eclipse 编译错误 Access restriction:The type *** is not accessible due to restriction on... 解决方案 Eclipse ...
- [Go]字典(map)的操作和约束
字典(map)存储的是键值对(key-value pair,一个键值对代表了一对键和值.一个键和一个值分别代表了一个从属于某一类型的独立值,把它们两个捆绑在一起就是键值对,也称“键-元素对”)的集合 ...
- 《TCP/IP详解卷1:协议》——第5章 RARP:逆地址解析协议(转载)
1.引言 具有本地磁盘的系统引导时,一般是从磁盘上的配置文件中读取IP地址.但是无盘机,如X终端或无盘工作站,则需要采用其他方法来获得IP地址. 网络上的每个系统都具有唯一的硬件地址,它是由网络接口生 ...
- [Poj2411]Mondriaan's Dream(状压dp)(插头dp)
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 18096 Accepted: 103 ...
- Codeforces 954 D Fight Against Traffic
Discription Little town Nsk consists of n junctions connected by m bidirectional roads. Each road co ...
- PCRE函数简介和使用示例
PCRE是一个NFA正则引擎,不然不能提供完全与Perl一致的正则语法功能.但它同时也实现了DFA,只是满足数学意义上的正则. PCRE提供了19个接口函数,为了简单介绍,使用PCRE内带的测试程序( ...
- Java调用WSDL接口
1.首先准备jar包: 2.代码调用如下: String url="url地址"; QName qName=new QName("命名空间","接口名 ...