struts配置。泪奔...
说多了都是泪啊,配置一个环境一天才搞定。不错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配置。泪奔...的更多相关文章
- tomcat+struts配置总结
忙活了好些天Tomcat和Struts配置,踩了好多坑 此文仅供参考,只是笔者自身的记录. 配置在这里就不赘述了,贴几个链接给你们参考把! 一.配置简述 jdk配置 https://blog.csdn ...
- struts配置通配符*来匹配方法,实现动态调用
01:web.xml中配置,启动struts2 <?xml version="1.0" encoding="UTF-8"?> <web-app ...
- 菜鸟学习Struts——配置Struts环境
刚开始学习Struts,它通过采用JavaServlet/JSP技术,实现了基于Java EEWeb应用的MVC设计模式的应用框架,是MVC经典设计模式中的一个经典产品. 要用到Struts就要学会配 ...
- Struts配置详解
一.Stuts的元素 1 web.xml 任何一个web应用程序都是基于请求响应模式进行构建的,所以无论采用哪种MVC框架,都离不开web.xml文件的配置.换句话说,web.xml并不是Struts ...
- webwork或Struts配置网站根路径的默认页面办法
参考资料:http://www.iteye.com/problems/24028 查阅好多资料,关于webwork或Struts处理默认页面的方式,能否像spring MVC那样直接指定默认访问页面. ...
- struts配置中的常量定义
一.常量可以在struts.xml或struts.properties中配置,建议在struts.xml中配置,两种配置方式如下: (1)在struts.xml文件中配置常量 <struts&g ...
- struts配置访问后缀为.do,.action,.*
Struts 配置文件的加载顺序 Struts-default.xml---> struts-plugin.xml--> struts.xml--> struts.propert ...
- struts配置测试中遇到报错信息,记录下
tomcat7 jdk7myeclipse2014 部署完成后,访问页面报错struts.xml文件内容: <?xml version="1.0" encoding=&quo ...
- struts配置请求后缀,将.action改为.do、.doaction_2015.01.04
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "- ...
随机推荐
- Understanding Convolution in Deep Learning
Understanding Convolution in Deep Learning Convolution is probably the most important concept in dee ...
- 更改DEVExpress的Column的DisplayFormat为自定义的方法。
更改DEVExpress的Column的DisplayFormat为自定义的方法. public partial class Form1 : XtraForm { public Form1() { I ...
- ASP.NET - 演练:创建网页以显示 XML 数据
数据通常是以 XML 格式提供给 Web 应用程序的.但是,XML 数据本质上是分层的,因此您可能希望能够在基于列表的控件中使用 XML 数据,如 GridView 或 DropDownList 控件 ...
- 测试c语言函数调用性能因素之测试三
函数调用:即调用函数调用被调用函数,调用函数压栈,被调用函数执行,调用函数出栈,调用函数继续执行的一个看似简单的过程,系统底层却做了大量操作. 操作: 1, 调用函数帧指针 ...
- visual studio 2012 Github
前言 一直以来都想使用Git来管理自己平时积累的小代码,就是除了工作之外的代码了.有时候自己搞个小代码,在公司写了,就要通过U盘或者网盘等等一系列工具进行Copy,然后回家才能继续在原来的基础上作业. ...
- UVA 562 Dividing coins
题目描述:给出一些不同面值的硬币,每个硬币只有一个.将这些硬币分成两堆,并且两堆硬币的面值和尽可能接近. 分析:将所有能够取到的面值数标记出来,然后选择最接近sum/2的两个面值 状态表示:d[j]表 ...
- Jquery 中map和each的区别
<script type="text/javascript"> $(function () { var json = {"Name":"L ...
- C# 设置程序开机自动运行(+注册表项)
有时候我们需要让软件安装好了,开机自动运行,这时我们需要把启动项加载到注册表中,需要注意的时现在很多杀毒软件在其他软件更改注册表的时候会有提示,可能会阻止.下面代码包含增加启动项到注册表和删除启动项. ...
- 最大 / 小的K个数
在<剑指offer>上看到的,而且Qunar去年的校招笔试也考了这题,今天晚上去西电腾讯的宣讲会,来宣讲的学长也说他当时一面的时候面试官问了“一亿个数据的最大的十个数”的面试题.今晚就写写 ...
- 在 eclipse 中设置每行的字数
在Preferences中:Java Code Style Formatter