说多了都是泪啊,配置一个环境一天才搞定。不错the requested resource (/login) is not available in struts,就是找不到什么什么class.亦或there is no action mapped for namespace / and action name。还有编码错误。反正是啥错误都有啊。各种百度,各种google.终于算是配置成功了。

第一步:下载struts-2.3.15.1。全部下吧,里面有包,有文档,有示例。我们需要的开发包在Lib文件夹里面。

第二步:第一步算是准备了材料,材料完了之后需要炒菜了,这就需要点耐心外加一定技巧了。首先在myeclipse里面新建一个web项目,既然是用struts开发,那么肯定少不了要添加很多的包,这样才能引用别人的成果不是?引用的包主要有(当然,不同版本可能会有一两个包不一样):commons-fileupload-1.3.jar、commons-io-2.0.1.jar、commons-lang3-3.1.jar、commons-logging-1.1.3.jar、commons-logging-api-1.1.jar、freemarker-2.3.19.jar、javassist-3.11.0.GA.jar、ognl-3.0.6.jar、struts2-core-2.3.15.1.jar、xwork-core-2.3.15.1.jar。

第三步:引入包之后,你就可以写jsp页面,web.xml和struts2.xml配置文件了。

先讲struts2的配置文件吧。一定记得struts2怎么拼写的,还有一些拼写问题,我也遇到了。总之,一点都不能错。struts2文件写好了之后,放在WebRoot\WEB-INF\classes文件夹里面。这个问题会害死你的,如果不注意。

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd"> <struts>
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
<package name="strut" extends="struts-default">
<action name="login" class="com.LoginAction">
<result name="success">/success.jsp</result>
</action>
</package>
</struts>

然后是web.xml的配置。注意其中的filter-class是:org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter。这个问题没搞懂,估计你会发现无数个error.can not find...class.全出来了。

 <?xml version="1.0" encoding="UTF-8"?>
<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">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<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>
</web-app>

配置文件搞定了,下面就轮到jsp页面了。我写了一个简单的页面。注意编码我已经改成pageEncoding="UTF-8"。否则可能会出现乱码的问题。你改成gb2312也是乱码,因为上面的配置文件貌似都是utf-8.

 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
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 'index.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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
This is my JSP page. <br>
<s:form action="login" method="post">
<s:label value="系统登陆"></s:label>
<s:textfield name="username" label="账号" />
<s:password name="password" label="密码" />
<s:submit value="登录" />
</s:form>
</body>
</html>

对了,还有一个响应class.他是LoginAction。我写的很简单,就是执行一个方法而已。

 package com;

 import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
public class LoginAction extends ActionSupport { public String excute() throws Exception{
return "success";
}
}

当然记得新建一个success.jsp的页面喔,否则成功后转到哪里去呢?

现在觉得貌似很简单。当时怎么那么多错误呢?催。。。Mark一下、sleepping..

struts配置。泪奔...的更多相关文章

  1. tomcat+struts配置总结

    忙活了好些天Tomcat和Struts配置,踩了好多坑 此文仅供参考,只是笔者自身的记录. 配置在这里就不赘述了,贴几个链接给你们参考把! 一.配置简述 jdk配置 https://blog.csdn ...

  2. struts配置通配符*来匹配方法,实现动态调用

    01:web.xml中配置,启动struts2 <?xml version="1.0" encoding="UTF-8"?> <web-app ...

  3. 菜鸟学习Struts——配置Struts环境

    刚开始学习Struts,它通过采用JavaServlet/JSP技术,实现了基于Java EEWeb应用的MVC设计模式的应用框架,是MVC经典设计模式中的一个经典产品. 要用到Struts就要学会配 ...

  4. Struts配置详解

    一.Stuts的元素 1 web.xml 任何一个web应用程序都是基于请求响应模式进行构建的,所以无论采用哪种MVC框架,都离不开web.xml文件的配置.换句话说,web.xml并不是Struts ...

  5. webwork或Struts配置网站根路径的默认页面办法

    参考资料:http://www.iteye.com/problems/24028 查阅好多资料,关于webwork或Struts处理默认页面的方式,能否像spring MVC那样直接指定默认访问页面. ...

  6. struts配置中的常量定义

    一.常量可以在struts.xml或struts.properties中配置,建议在struts.xml中配置,两种配置方式如下: (1)在struts.xml文件中配置常量 <struts&g ...

  7. struts配置访问后缀为.do,.action,.*

    Struts 配置文件的加载顺序 Struts-default.xml---> struts-plugin.xml--> struts.xml-->   struts.propert ...

  8. struts配置测试中遇到报错信息,记录下

    tomcat7 jdk7myeclipse2014 部署完成后,访问页面报错struts.xml文件内容: <?xml version="1.0" encoding=&quo ...

  9. struts配置请求后缀,将.action改为.do、.doaction_2015.01.04

    <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "- ...

随机推荐

  1. UML标准图(转载)

    在前面的章节中,我们已经讨论过的构建和其他必要的UML元素.现在,我们需要明白的地方使用这些元素. 元素都可以以不同的方式,使一个被称为图的完整的UML图片,如:组件.所以这是非常重要的,要了解不同的 ...

  2. sourcemap的使用

    minify.bat @echo off if ""%1""=="""" goto end :loop if not e ...

  3. 哪些问题困扰着我们?DevOps 使用建议

    [编者按]随着 DevOps 被欲来越多机构采用,一些共性的问题也暴露出来.近日,Joe Yankel在「Devops Q&A: Frequently Asked Questions」一文中总 ...

  4. JavaScript 性能分析新工具 OneProfile

    OneProfile 是一个网页版的小工具,可以用全新的方式展示 JavaScript 性能分析的结果,帮助开发者洞悉函数调用关系,优化应用性能. 点击打开 OneProfile 背景 Chrome ...

  5. swift-基础部分

    变量常量,注释,分号,整数,浮点数.数值行类型转换,类型别名,波尔值,元组,可选,断言              let binaryInteger = 0b10001  let twoThousan ...

  6. iOS验证码倒计时(GCD实现)

    + (void)verificationCode:(void(^)())blockYes blockNo:(void(^)(id time))blockNo { __block ; //倒计时时间 d ...

  7. HDU 1789 Doing Homework again (贪心)

    Doing Homework again http://acm.hdu.edu.cn/showproblem.php?pid=1789 Problem Description Ignatius has ...

  8. ExtJs之Ext.util.MixedCollection

    <!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...

  9. 记一段使用node对mysql数据库做处理

    所用到的存储过程如下: temp_get_userCount: BEGIN #Routine body goes here... SELECT COUNT(id) as num FROM tbl_us ...

  10. springMVC视频教程

    http://edu.51cto.com/index.php?do=lession&id=42165