Struts2当调用action时出现HTTP Status 404 问题解决
来源:互联网 发布:淘宝英文 编辑:程序博客网 时间:2024/05/04 06:04
之前碰到这一个问题,在网上查找解决方法,改了两天也没有解决,今天重新建了一个工程一开始还是出错了,后来查看Console的信息发现以下问题:
严重: Exception starting filter struts2java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtilsat com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:213)at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:102)at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:240)at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:970)at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:438)at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:482)at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:57)at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4908)at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5602)at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1572)at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1562)at java.util.concurrent.FutureTask.run(FutureTask.java:266)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)at java.lang.Thread.run(Thread.java:745)Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtilsat org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1858)at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1701)... 21 more
发现缺少了一个包,就是commons-lang3-3.2.jar这个包,添加进去后问题就解决了,下面一步一步建立可以执行的这个工程
首先,我的工程结构如下:
注意,复制到WebContent下的WEB-INF下的lib中的jar包总共有以下12个!
第一步,创建工程的时候勾选自动创建web.xml文件,如下图点击next
进入如下界面,再点击next
进入下一个界面,勾选Generate web.xml deployment descriptor,再点击finish就可以创建出web.xml文件了
编写web.xml的配置信息,注意Struts2使用的过滤器类是org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter,以下为我的web.xml的代码:
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>StrutsDemo02</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <filter> <!-- 定义核心Filter的名字 --> <filter-name>struts2</filter-name> <!-- 定义核心Filter的实现类 --> <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>
然后,在src文件右击选择New->Other,在弹出的文本框中的General选项下选择“file”,点击next,将文件名命名为struts.properties,完成后在struts.properties文件中写入
<struts.i18n.encoding value="UTF-8"/>接下来在src文件夹下创建struts.xml,我的代码如下,文件中声明了一个名字为hello的action,该action对应的类为com.action.TestAction,返回结果为success.jsp页面
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"><struts> <package name="default" namespace="/" extends="struts-default"> <action name="hello" class="com.action.TestAction" > <result>/success.jsp</result> </action> </package></struts>然后在src下创建包com.action,在包下创建TestAction.java,我的代码如下
import com.opensymphony.xwork2.ActionSupport;public class TestAction extends ActionSupport {/** * */private static final long serialVersionUID = 1L;private String helo;//helo的getter与setterpublic String getHelo() {return helo;}public void setHelo(String hello) {this.helo = hello;}@Overridepublic String execute() throws Exception {// TODO Auto-generated method stubhelo="hello struts";return SUCCESS;}}
最后,在WebContent下创建index.jsp文件与success.jsp文件,写jsp页面时要注意在头部加上<%@ taglib prefix="s" uri="/struts-tags"%>,引入struts的标签库
index.jsp文件内容
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%><%@ taglib prefix="s" uri="/struts-tags"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Insert title here</title></head><body><!-- Struts的超链接标签,链接一个名为hello的action --><s:a action="hello">hello</s:a></body></html>
success.jsp页面内容
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%><%@ taglib prefix="s" uri="/struts-tags"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Insert title here</title></head><body><s:property value="helo"/></body></html>到此,右键工程,Run on Sever就成功了!
点击hello
0 0
- Struts2当调用action时出现HTTP Status 404 问题解决
- 在部署Struts时,出现如下错误信息:HTTP Status 404 - Servlet action is not available
- Struts2:HTTP Status 404 - There is no Action mapped for namespace[ / ]and action name singleUpload.
- Struts2框架中HTTP Status 404 There is no Action mapped for namespace / and action name
- struts hibernate spring 环境配置时出现 HTTP Status 404 Servlet action is not available (解决方法)
- struts2 上传文件 HTTP Status 404 - No result defined for action.....and result input
- HTTP Status 404 - /deinterceptor/test.action ------------------------------------------------------
- struts.xml不在默认位置,导致出现HTTP Status 404 - There is no Action mapped for namespace [/] and action name [
- Struts2-当action中有多个用方法名调用方法
- Struts2报错:HTTP Status 404
- HTTP Status 404 - No result defined for action EmployeeAction and result input - struts2类似异常解决及原因剖析
- 当编写Servlet时出现type Status report message HTTP method GET is not supported by this URL description The
- strust框架下默认Action default-action-ref 出现HTTP Status 500错误
- struts2的上传文件大小限制引起HTTP Status 404 - No result defined for action com.cpms.action.organ.UploadFile and result inpu
- HTTP Status 404 - Servlet action is not available
- HTTP Status 404 - Servlet action is not available
- Struts:HTTP Status 404 - Servlet action is not available
- HTTP Status 404 - Servlet action is not available
- 根据2个经纬度点,计算这2个经纬度点之间的距离(通过经度纬度得到距离)
- 多页面浏览器中数据管理的方法及浏览器
- python学习(三):高级特性
- 第一次写博客
- 线程、线程句柄、线程ID
- Struts2当调用action时出现HTTP Status 404 问题解决
- MySQL 存储过程和存储函数示例
- 图像高斯滤波的FPGA实现--实时高速
- Unity 2d 开发实战
- <![CDATA]>
- Linux系统中如何添加自己的库文件路径
- Linux安装mysql 缺少ncurses-devel包
- Understanding Basic Multithreading Concepts
- 抽象工厂模式