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 "- ...
随机推荐
- 获取app版本号
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; NSString *name = [infoDiction ...
- 将HTML转成XHTML并清除一些无用的标签和属性
介绍 这是一个能帮你从HTML生成有效XHTML的经典库.它还提供对标签以及属性过滤的支持.你可以指定允许哪些标签和属性可在出现在输出中,而其他的标签过滤掉.你也可以使用这个库清理Microsoft ...
- 使用Assetbundle时可能遇到的坑
原地址:http://www.cnblogs.com/realtimepixels/p/3652128.html 一 24 十一郎未分类 No Comments 转自 http://www.unity ...
- Sqli-labs less 52
Less-52 和less50是一样的,只是这里的mysql错误不会在前台显示,但是对于stacked injection是一样的利用方式 http://127.0.0.1/sqli-labs/Les ...
- 如何使用 Docker 部署一个基于 Play Framework 的 Scala Web 应用?
本文作者 Jacek Laskowski 拥有近20年的应用程序开发经验,现 CodiLime 的软件开发团队 Leader,曾从 IBM 取得多种资格认证.在这篇博文中,Jacek 分享了 Wars ...
- Spring mvc json null
http://blog.csdn.net/zdsdiablo/article/details/9429263
- C#保留小数位数
1.System.Globalization.NumberFormatInfo provider = new System.Globalization.NumberFormatInfo(); prov ...
- C#计算时间差值
/// <summary> /// 计算时间差值 /// </summary> /// <param name="DateTime1">< ...
- GET和POST测试(支持需要登录的接口调用:高级功能->填写cookie)
http://coolaf.com
- 李洪强漫谈iOS开发[C语言-005]-程序结构分析