`
oppovaan
  • 浏览: 2115 次
  • 性别: Icon_minigender_1
  • 来自: 福建
最近访客 更多访客>>
社区版块
存档分类
最新评论

搭建Struts2环境

阅读更多
1、要先下载Struts2的jar包,核心包:common-loggin-1.0.4.jar,freemarker-2.3.8.jar,ognl-2.6.11.jar,struts2-core-2.0.14.jar,xwork-2.0.7.jar(版本可能不同),将这些包复制到WEB-INF/lib文件夹下。

2 、编辑web.xml,配置struts2核心Filter。
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 
	xmlns="http://java.sun.com/xml/ns/j2ee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
	http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <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-mapping>
  	<filter-name>struts2</filter-name>
  	<url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>


3、建立一个简单提交请求页面
<%@ page language="java" pageEncoding="GBK"%>
<%@ taglib prefix="s" uri="/struts-tags" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
  <head>
    <html:base />
    
    <title>test.jsp</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">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
   	<form action="Login.action" method="post">
   		<table align="center">
   			<tr><td>用户名<input type="text" name="username" /> </td></tr>
   			<tr><td>密码<input type="text" name="password" /></td></tr>
   			<tr><td colspan="2"><input type="submit" value="登录" /> </td></tr>
   		</table>
   	</form>
  </body>
</html:html>


4、创建Action
public class LoginAction {

	private String username;
	private String 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(){
		
		if("admin".equals(getUsername())&&"admin".equals(getPassword())){
			return "success";
		}
		else{
			return "error";
		}
	}
	
}


5、在src目录下创建一个struts.xml文件,将Action配置在web应用中
<?xml version="1.0" encoding="UTF-8"?>
	<!-- 指定Struts 2配置文件的DTD信息 -->

<!DOCTYPE struts PUBLIC

        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

        "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
	<package name="struts2test" extends="struts-default">
		<action name="Login" class="com.struts2.test.LoginAction">
			<result name="success">/welcome.jsp</result>
			<result name="error">/login.jsp</result>
		</action>
	</package>
</struts>


6、增加测试跳转成功页面
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>

<!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">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
  登陆成功<br/>
   欢迎你:${username }
  </body>
</html>


启动Tomcat。运行http://localhost:8080/struts2/login.jsp
分享到:
评论
2 楼 oppovaan 2010-06-30  
从错误上面看,好像是你的配置文件写错了吧,无法载入 你检查下struts.xml
1 楼 gylixyu 2010-06-22  
2010-6-22 2:18:12 org.apache.catalina.core.AprLifecycleListener init

信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: E:\Users\lixyu\AppData\Local\Genuitec\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\bin;E:\Program Files\Apache Software Foundation\Tomcat 6.0\bin
2010-6-22 2:18:12 org.apache.coyote.http11.Http11Protocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2010-6-22 2:18:12 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 700 ms
2010-6-22 2:18:12 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2010-6-22 2:18:12 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.20
2010-6-22 2:18:14 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-default.xml]
2010-6-22 2:18:15 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Unable to locate configuration files of the name struts-plugin.xml, skipping
2010-6-22 2:18:15 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-plugin.xml]
2010-6-22 2:18:15 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts.xml]
2010-6-22 2:18:16 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
严重: Dispatcher initialization failed
Unable to load configuration. - action - file:/E:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/struts2Test/WEB-INF/classes/struts.xml:7:61
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:374)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:418)
at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:190)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:397)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3800)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4450)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:987)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:909)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:495)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1206)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:314)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: Action class [com.struts2.test.LoginAction] not found - action - file:/E:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/struts2Test/WEB-INF/classes/struts.xml:7:61
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:409)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:354)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:468)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:264)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:111)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:193)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)
... 30 more
2010-6-22 2:18:16 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter struts2
Unable to load configuration. - action - file:/E:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/struts2Test/WEB-INF/classes/struts.xml:7:61
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:431)
at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:190)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:397)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3800)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4450)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:987)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:909)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:495)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1206)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:314)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: Unable to load configuration. - action - file:/E:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/struts2Test/WEB-INF/classes/struts.xml:7:61
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:374)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:418)
... 28 more
Caused by: Action class [com.struts2.test.LoginAction] not found - action - file:/E:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/struts2Test/WEB-INF/classes/struts.xml:7:61
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:409)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:354)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:468)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:264)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:111)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:193)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)
... 30 more
2010-6-22 2:18:16 org.apache.catalina.core.StandardContext start
严重: Error filterStart
2010-6-22 2:18:16 org.apache.catalina.core.StandardContext start
严重: Context [/struts2Test] startup failed due to previous errors
2010-6-22 2:18:17 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2010-6-22 2:18:17 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
2010-6-22 2:18:17 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/50  config=null
2010-6-22 2:18:17 org.apache.catalina.startup.Catalina start
信息: Server startup in 4398 ms
我按照你上面的做了出现这个错误是为什么呢?我用的是tomcat6.0+myeclipse8.5

相关推荐

    Eclipse下搭建Struts2环境.doc

    【标题】:Eclipse下搭建Struts2环境 【描述】:本文档将详细介绍如何在Eclipse集成开发环境中搭建Struts2的开发环境,适合Java初学者和需要更新技能的专业人士。内容包括所需软件的下载地址、安装步骤以及配置过程...

    手动搭建struts2环境

    手动搭建Struts2环境涉及多个步骤,包括安装必要的软件、配置环境变量以及整合项目依赖。 首先,我们需要准备以下基础软件: 1. **JDK**:Struts2是Java平台上的框架,因此需要安装Java Development Kit(JDK)并...

    struts-2.3.34-normal-搭建struts2环境

    如何搭建struts2环境——/struts-normal/如何搭建struts2环境.txt

    马士兵老师搭建struts2环境时用到的jar架包

    1. **Struts2核心库**:这是搭建Struts2环境的基础,主要包括`struts2-core.jar`,它包含了Action、Interceptor、Result等核心组件。 2. **OGNL(Object-Graph Navigation Language)**:Struts2使用OGNL作为表达式...

    搭建Struts2环境所需jar包

    搭建Struts2环境所需jar包: commons-logging-1.0.4.jar freemarker-2.3.8.jar ognl-2.6.11.jar struts2-core-2.0.11.1.jar xwork-2.0.4.jar

    搭建struts2的jar包

    在搭建Struts2环境时,jar包是核心组成部分,它们包含了运行Struts2应用所需的类和库。 首先,让我们来理解一下为什么需要这些jar包。Struts2框架依赖于多个库,包括核心库、依赖注入、异常处理、国际化、插件支持...

    第一节 搭建struts2环境

    在本节中,我们将深入探讨如何搭建Struts2开发环境,这是Java Web应用程序开发中的一个关键步骤。Struts2是一个流行的MVC(Model-View-Controller)框架,它提供了强大的功能来构建结构清晰、可维护性高的Web应用。...

    搭建struts2简单环境

    接下来,我们开始搭建Struts2环境: 1. **创建Maven项目**: 打开你的IDE,选择新建Maven项目,按照向导步骤操作。确保在pom.xml文件中添加Struts2的核心依赖。例如: ```xml &lt;groupId&gt;org.apache.struts ...

    Struts2框架搭建

    搭建Struts2环境的第一步是添加必要的库到项目中。这通常涉及在项目的`pom.xml`文件中添加Struts2的相关依赖,如`struts2-core`、`struts2-convention-plugin`等。如果你使用的是Eclipse或IntelliJ IDEA等IDE,可以...

    struts2环境搭建

    首先,要开始搭建Struts2环境,你需要访问Apache Struts的官方网站(http://struts.apache.org/)。在这里,你可以找到最新的版本。点击右上角的“struts2”,然后选择“Download Now”来下载Full Distribution。这...

    struts2环境搭建+struts2 新闻发布系统+struts2 留言板

    struts2环境搭建+struts2 新闻发布系统+struts2 留言板 struts2环境搭建:基础框架搭建,简单易上手,适合新手,比你看书强多了,实践源于理论而高于理论,贵在实践 朋友。 struts2 新闻发布系统:struts2+jsp 功能不...

    传智播客struts2.1视频教程_介绍struts2及struts2开发环境的搭建

    本视频教程由传智播客提供,旨在帮助初学者理解Struts2的基础概念,并指导如何搭建Struts2的开发环境。 首先,我们要了解Struts2的核心概念。Struts2是一个基于MVC(Model-View-Controller)设计模式的框架,它的...

    struts2环境搭建及国际化

    在搭建Struts2环境的过程中可能会遇到一些常见问题,以下是一些典型的解决方案: **3.1 编译错误** - 如果出现Java版本不匹配的问题,请检查项目的编译版本是否正确设置为1.6。 - 检查Maven的依赖库是否正确添加。...

    struts2开发环境的搭建

    本文将详细介绍如何搭建Struts2开发环境,并提供三种不同的方法来帮助读者快速上手。无论是初学者还是有一定经验的开发者,都能从中找到适合自己的方式。 #### 二、准备工作 在开始之前,请确保已经安装了以下工具...

    搭建Struts2开发环境

    搭建 Struts2 开发环境 Struts2 是一个基于 Java 语言的 Web 应用程序框架,提供了一个灵活的、可扩展的、基于 MVC 模式的开发环境。为了搭建 Struts2 开发环境,需要完成以下四个步骤: 1. 建立工程 首先,需要...

    Struts2教学视频

    **二、搭建Struts2的运行环境** 搭建Struts2环境通常包括以下几个步骤: 1. 引入Struts2的核心库依赖到项目中,这通常是在Maven或Gradle的pom.xml或build.gradle文件中添加对应的依赖。 2. 配置web.xml文件,将...

    Struts2环境.doc

    以下是对搭建Struts2环境的详细步骤的说明: 1. 创建Web项目:首先,你需要在IDE(如Eclipse或IntelliJ IDEA)中创建一个新的Web项目。确保选择JEE5.0作为项目的Java版本,因为Struts2支持这个平台。 2. 配置...

Global site tag (gtag.js) - Google Analytics