说多了都是泪啊,配置一个环境一天才搞定。不错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. Codeforces Round #349 (Div. 1) B. World Tour 最短路+暴力枚举

    题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一 ...

  2. POJ2676-Sudoku(数独)

    想了好久没想到好的解决办法,参考了 http://user.qzone.qq.com/289065406/blog/1303713313 大致题意: 九宫格问题,也有人叫数独问题 把一个9行9列的网格 ...

  3. 【Dancing Link专题】解题报告

    DLX用于优化精确覆盖问题,由于普通的DFS暴力搜索会超时,DLX是一个很强有力的优化手段,其实DLX的原理很简单,就是利用十字链表的快速删除和恢复特点,在DFS时删除一些行和列以减小查找规模,使得搜 ...

  4. cordova /phonegap 自定义插件

    ### cordova /phonegap 自定义插件 在使用cordova 的过程中,虽然官方提供的插件以及其他人开源的插件较多.但有时为了实现某种需求,还是需要自己编写插件. 以前总是会手动的配置 ...

  5. nginx+php+flight 构建RESTFul API

    配置: Nginx: conf目录下nginx.conf配置文件. 第44行改为:root   D:/wwwroot/www; 第45行改为:index  index.html index.htm i ...

  6. [工作积累] android 中添加libssl和libcurl

    1. libssl https://github.com/guardianproject/openssl-android 然后执行ndk-build 2.libcurl 源代码组织结构, 下面的mak ...

  7. 无法解决 equal to 运算中 &quot;Chinese_PRC_CI_AS&quot; 和 &quot;SQL_Latin1_General_CP1_CI_AS&quot; 之间的排序规则冲突。

    什么是排序规则(collation) 关于SQL Server的排序规则,估计大家都不陌生,在创建数据库时我们经常要选择一种排序规则(conllation),一般我们会留意到每一种语言的排序规则都有许 ...

  8. ios后台下载

    http://www.cocoachina.com/industry/20131106/7304.html

  9. Request/Server模式

    Request-------HTTP/SOAP----------Server Request模块只是Client的一小部分,Client还有HTML, Data(Text/JSON/HTML/XML ...

  10. Yarn的服务库和事件库

    对于生命周期较长的对象,YARN采用了基于服务对象管理模型对其进行管理. 该模型有一下特点: 每个被服务化的对象都分为4个状态 任何服务状态变化都可以触发另外一些动作 可以通过组合方式对任意服务进行组 ...