2 xiaohuihui183 xiaohuihui183 于 2015.07.26 11:10 提问

Struts2+Tomcat报404错误

今天在学Struts2时,测试一下登陆验证功能,部署到Tomcat上出现404
就是在访问http://localhost:8080/Struts2Pro/login.jsp时,出现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">
  <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

9个回答

miracle_yao
miracle_yao   2015.07.26 11:13

404是找不到页面,是不是Action的路径配错了

xiaohuihui183
xiaohuihui183 回复miracle_yao: 是呀,我也很郁闷
2 年多之前 回复
miracle_yao
miracle_yao 回复xiaohuihui183: 看上去访问路径没错啊
2 年多之前 回复
xiaohuihui183
xiaohuihui183 访问登陆界面就不行
2 年多之前 回复
CSDNXIAON
CSDNXIAON   2015.07.26 11:21

struts2 404错误
Tomcat正常启动后,报404错误
struts2 捕获404错误
----------------------同志你好,我是CSDN问答机器人小N,奉组织之命为你提供参考答案,编程尚未成功,同志仍需努力!

zjq78577117
zjq78577117   2015.07.26 11:52

错误信息帖出来,就是在访问http://localhost:8080/Struts2Pro/login.jsp时,出现404,你确定是否访问jsp页面时出错的?访问jsp应该不会出问题的,因为你的jsp放在了WebRoot下,可以直接访问的。

zjq78577117
zjq78577117 回复xiaohuihui183: 加我qq,我远程给你看下,397760767
2 年多之前 回复
xiaohuihui183
xiaohuihui183 错误提示在楼下
2 年多之前 回复
xiaohuihui183
xiaohuihui183   2015.07.26 11:55

图片说明

Evankaka
Evankaka   Ds   Rxr 2015.07.26 12:20

这个肯定是拦截器有问题,在Java类打个断点,看看是否有进去工作了!

myxzf
myxzf   2015.07.26 12:58

TomCat正常启动了吗?我有时遇到配置文件不规范,导致404错误的情况

xiaohuihui183
xiaohuihui183 Tomcat报错,貌似是过滤器的额问题
2 年多之前 回复
cuiwei1026522829
cuiwei1026522829   Ds   Rxr 2015.07.26 14:06

struts.xml少写一个namespace=“/”

xiaohuihui183
xiaohuihui183 加了,没用
2 年多之前 回复
a510835147
a510835147   2015.07.26 17:11

应该是发布项目时就报错了,可以把那个错贴上来看下嘛?

a510835147
a510835147 回复xiaohuihui183: <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> 在web.xml中看下是否配置了这个
2 年多之前 回复
a510835147
a510835147 回复xiaohuihui183: http://javeye.iteye.com/blog/940122/ 参考下这个
2 年多之前 回复
a510835147
a510835147 回复xiaohuihui183: http://javeye.iteye.com/blog/940122/ 参考下这个
2 年多之前 回复
xiaohuihui183
xiaohuihui183 已贴
2 年多之前 回复
tongyi55555
tongyi55555   2015.07.26 17:44


你这个里面的类名是大写的L,而实际给的java文件中使用的是小写的,是你贴错了还是IDE中就是这样。检查下。

建议你先解决tomcat启动报错的问题,如果tomcat启动时就有错,把错误贴出来看看。

xiaohuihui183
xiaohuihui183 回复JonsonJiao: 我只有struts啊,可是会报spring的错误,我也很郁闷
2 年多之前 回复
tongyi55555
tongyi55555 回复xiaohuihui183: 没有看到是有spring的东西的,你用spring做什么,你的配置中看不到这些啊。
2 年多之前 回复
xiaohuihui183
xiaohuihui183 回复JonsonJiao: 这个是jar包里的
2 年多之前 回复
tongyi55555
tongyi55555 回复xiaohuihui183: com/opensymphony/xwork2/spring/SpringObjectFactory.java:230看下这一行有什么问题不,打个断点。
2 年多之前 回复
xiaohuihui183
xiaohuihui183 已贴
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片