struts2.5.20配置的一些坑,HTTP Status 404-Not Found

1.Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.但控制台里除了警告信息没其他异常报错,这第一想法就是路径错误了

为了方便阅读经常把项目名称搞成中文,以前写java代码也没遇到坑,这次遇到了,Message部分显示的路径中间有一段编码,显然没有正常解析中文路径,所以把项目名改成全英文就行了;还有常见路径问题应该就是index.jsp放错文件夹,一般是在WebContent下面,不是在Web-INF文件夹下

2.Console报出异常错误:ERROR com.opensymphony.xwork2.util.DomHelper - 文档无效: 找不到语法。 at (null:3:8)

struts.xml 我以为就是个简单的xml所以随手新建了一个,忘了里面有个dtd约束,一般直接创建xml是没有的

所以要在struts.xml头部添加

<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
    "http://struts.apache.org/dtds/struts-2.5.dtd">

3.ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...报错提示需要添加 log4j-core的jar包

struts2.5.20提供了一个最小包,

我们看到最小包中没有log4j-core-2.11.1.jar这个包,在struts中lib也没发现有。

那么我们可以去下载一个,下载链接http://www.apache.org/dyn/closer.lua/logging/log4j/2.11.1/apache-log4j-2.11.1-bin.zip

点击图中链接进行下载,解压下载的压缩包。


找到log4j-core-2.11.1.jar包,拷贝到项目的lib目录下


--------------------- 
原文:https://blog.csdn.net/qq_39123517/article/details/88054810 
 

4.一般在WebINF/lib下添加了log4-core的jar包还会报错误

ERROR StatusLogger No Log4j 2 configuration file found. Using default configuration (logging only errors to the console), or user programmatically provided configurations. Set system property 'log4j2.debug' to show Log4j 2 internal initialization logging. See https://logging.apache.org/log4j/2.x/manual/configuration.html for instructions on how to configure Log4j 2
这时需要在classpath中(一般在src下面)添加log4j2.xml文件,2一定不能忘,文件名写错了还是同样错误

下面是log4j2.xml的具体配置:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="[%-5p] %d %c - %m%n" />
        </Console>
        <File name="File" fileName="dist/my.log">
            <PatternLayout pattern="%m%n" />
        </File>
    </Appenders>
 
    <Loggers>
        <Logger name="mh.sample2.Log4jTest2" level="INFO">
            <AppenderRef ref="File" />
        </Logger>
        <Root level="INFO">
            <AppenderRef ref="Console" />
        </Root>
    </Loggers>
</Configuration>

希望能帮到大家,记得点赞哈哈哈哈

发布了2 篇原创文章 · 获赞 3 · 访问量 436
展开阅读全文

Struts2+Tomcat报404错误

07-26

今天在学Struts2时,测试一下登陆验证功能,部署到Tomcat上出现404 就是在访问http://localhost:8080/Struts2Pro/login.jsp时,出现404 ![图片说明](https://img-ask.csdn.net/upload/201507/26/1437880230_607940.png) web.xml ``` <?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> ``` struts.xml ``` <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <package name="struts2" extends="struts-default"> <action name="login" class="com.test.action.LoginAction"> <result name="input">login.jsp</result> <result>/result.jsp</result> <result name="failer">/login.jsp</result> </action> </package> </struts> ``` LoginAction.java ``` package com.test.action; import com.opensymphony.xwork2.ActionSupport; public class loginAction extends ActionSupport { private String username; private String password; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Override public void validate() { // TODO Auto-generated method stub System.out.println("进入validate方法进行校验"); if(null==this.getUsername()|| "".equals(this.getUsername().trim())) { this.addFieldError("username", "请输入用户名"); } if(null==this.getPassword()||"".equals(this.getPassword().trim())) { this.addFieldError("password", "请输入密码"); } } @Override public String execute() throws Exception { // TODO Auto-generated method stub if("zy".equals(this.getUsername().trim())&&"123".equals(this.getPassword().trim())) { return "success"; } else { this.addFieldError("username", "username or password error!!!!"); return "failer"; } } } ``` Tomcat的报错 ``` 严重: Exception starting filter struts2 Class: com.opensymphony.xwork2.spring.SpringObjectFactory File: SpringObjectFactory.java Method: getClassInstance Line: 230 - com/opensymphony/xwork2/spring/SpringObjectFactory.java:230:-1 at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:502) 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:4854) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5546) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.startup.HostConfig.reload(HostConfig.java:1533) at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1497) at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1695) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:333) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117) at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90) at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1374) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1546) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1556) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1524) at java.lang.Thread.run(Thread.java:619) Caused by: java.lang.NullPointerException at com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance(SpringObjectFactory.java:230) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyResultType(XmlConfigurationProvider.java:604) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addResultTypes(XmlConfigurationProvider.java:574) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:530) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:292) at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:112) at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:250) at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67) at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:446) at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:490) ... 19 more 2015-7-26 15:56:09 org.apache.catalina.core.StandardContext startInternal 严重: One or more Filters failed to start. Full details will be found in the appropriate container log file 2015-7-26 15:56:09 org.apache.catalina.core.StandardContext startInternal 严重: Context [/Struts2New] startup failed due to previous errors ``` 问答

struts2没有调用action类自定义的方法,跳转404

09-26

一直没有调用action方法,控制台无报错信息,登陆跳转404。 web.xml: ``` <?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"> <display-name></display-name> <welcome-file-list> <welcome-file>login.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>*.action</url-pattern> </filter-mapping></web-app> ``` struts.xml: ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" "http://struts.apache.org/dtds/struts-2.5.dtd"> <struts> <constant name="struts.action.extension" value="true" /> <package name="strut2" extends="struts-default"> <action name="Login" class="loginAction.LoginAction" method="user"> <result name="usersuccess">/user.jsp</result> <result name="adminsuccess">/admin.jsp</result> <result name="fail">/fail.jsp</result> </action> </package> </struts> ``` 试过将method改为函数名称,也试过删去<constant> aciton类: ``` package loginAction; public class LoginAction { private String account; public String getAccount(){ return account; } public void setAccount(String account){ this.account=account; } private String password; public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String user()throws Exception{ System.out.print('1'); if(account.equals(password)){ System.out.println("执行user方法"); return "usersuccess"; } return "fail"; } public String admin()throws Exception{ if(account.equals(password)){ System.out.println("执行admin方法"); return "adminsuccess"; } return "fail"; } } ``` 试过删去set,get方法不行,函数没有调用(控制台无1输出) login.jsp ``` <%@ page contentType="text/html;charset=UTF-8" language="java" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <body> 普通用户登录: <form action = "login-user" method="post"> 请您输入账号:<input name="account" type="text"><br> 请您输入密码:<input name="password" type="password"> <input type="submit" value="登录"> </form><br> 管理员用户登录: <form action = "login-admin" method="post"> 请您输入账号:<input name="account" type="text"><br> 请您输入密码:<input name="password" type="password"> <input type="submit" value="登录"> </form> </body> </html> ``` 试过将action 改为/形式 其他三个登陆成功(失败)页面相似: ``` <%@ page contentType="text/html;charset=UTF-8" language="java" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <body> 普通用户登陆成功。 </body> </html> ``` 确认struts2包齐全,由myeclipse内部struts2.2.1,struts.xml也在tomcat中的class文件夹中生成 问答

struts2 找不到action 页面404

06-11

QAQ大晚上的有没有人啊啊啊啊呜呜呜 struts.xml <?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="DoudouShop" extends="struts-default"> <action name="login" class="doudou.struts.aciton.AdminAction"> <result name="success">/loginsuccess.jsp</result> <result name="error">/loginerror.jsp</result> </action> </package> </struts> 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/j2ee" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <display-name>DoudouShop</display-name> <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> AdminAction.java package doudou.struts.action; import com.opensymphony.xwork2.ActionSupport; import doudou.service.AdminServiceImpl; public class AdminAction extends ActionSupport { private String adminType; private String loginPwd; private String loginName; private String adminName; public String getAdminType() { return adminType; } public void setAdminType(String adminType) { this.adminType = adminType; } public String getLoginPwd() { return loginPwd; } public void setLoginPwd(String loginPwd) { this.loginPwd = loginPwd; } public String getLoginName() { return loginName; } public void setLoginName(String loginName) { this.loginName = loginName; } public String getAdminName() { return adminName; } public void setAdminName(String adminName) { this.adminName = adminName; } public String adminLogin() throws Exception{ AdminServiceImpl b=new AdminServiceImpl(); if(b.adminLogin(loginName, loginPwd)==null) return"success"; else return"error"; } } 我运行最基本的jsp(没加任何内容) 还是显示404啊为什么啊 六月 12, 2016 12:55:27 上午 org.apache.catalina.core.StandardContext startInternal 严重: One or more Filters failed to start. Full details will be found in the appropriate container log file 六月 12, 2016 12:55:27 上午 org.apache.catalina.core.StandardContext startInternal 严重: Context [/DoudouMall] startup failed due to previous errors 六月 12, 2016 12:55:28 上午 org.apache.catalina.startup.TldConfig execute 信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. log4j:WARN No appenders could be found for logger (com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. 六月 12, 2016 12:55:29 上午 org.apache.catalina.core.StandardContext filterStart 严重: Exception starting filter struts2 Unable to load configuration. - action - file:/D:/JEEworkspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/DoudouShop/WEB-INF/classes/struts.xml:7:71 at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:501) 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(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: Unable to load configuration. - action - file:/D:/JEEworkspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/DoudouShop/WEB-INF/classes/struts.xml:7:71 at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70) at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:445) at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:489) ... 14 more Caused by: Action class [doudou.struts.aciton.AdminAction] not found - action - file:/D:/JEEworkspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/DoudouShop/WEB-INF/classes/struts.xml:7:71 at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:482) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:426) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:552) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:292) at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:112) at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:258) at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67) ... 16 more 六月 12, 2016 12:55:29 上午 org.apache.catalina.core.StandardContext startInternal 严重: One or more Filters failed to start. Full details will be found in the appropriate container log file 六月 12, 2016 12:55:29 上午 org.apache.catalina.core.StandardContext startInternal 严重: Context [/DoudouShop] startup failed due to previous errors 六月 12, 2016 12:55:29 上午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["http-bio-8080"] 六月 12, 2016 12:55:29 上午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["ajp-bio-8009"] 六月 12, 2016 12:55:29 上午 org.apache.catalina.startup.Catalina start 信息: Server startup in 12908 ms 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览