iteye_814
iteye_814
2012-05-06 11:25

初步使用struts2的一个问题,纠结了半天,熟悉struts2的帮忙看看

  • it技术
  • 互联网问答
  • IT行业问题
  • 编程语言问答
  • 计算机技术

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.FilterDispatcher</filter-class>
        <init-param> 
            <param-name>actionPackages</param-name> 
            <param-value>com.wrk.bi.action</param-value> 
        </init-param> 
    </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.1//EN"
        "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
    <constant name="struts.devMode" value="true" />
    <constant name="struts.mapper.composite" value="struts" />
    <constant name="struts.convention.default.parent.package" value="default-package" />
    <constant name="struts.i18n.encoding" value="UTF-8" />
    <constant name="struts.locale" value="zh_CN" />
    <constant name="struts.multipart.maxSize" value="100000000" />
    <package name="default-package" extends="struts-default">
        <global-results>
            <result name="failure">/common/exception.jsp</result>
        </global-results>
        <global-exception-mappings>
            <exception-mapping name="runtimeexception" exception="java.lang.RuntimeException" result="failure" />
        </global-exception-mappings>
    </package>
</struts>

 

Action类代码:

package com.wrk.bi.action;


import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
@Namespace("ref/WorkDeploy")
public class WorkDeployAction extends ActionSupport{

    private String SUCCESS;
    
    private String ERROR;
    
    @Action(value = "queryWork")
    public String queryWork(){
        System.out.println("2222222222");
        return SUCCESS;
    }

    public String getSUCCESS() {
        return SUCCESS;
    }

    public void setSUCCESS(String success) {
        SUCCESS = success;
    }

    public String getERROR() {
        return ERROR;
    }

    public void setERROR(String error) {
        ERROR = error;
    }   
    
    
}

 

报错:

Struts Problem Report

Struts has detected an unhandled exception:

Messages:  
File: org/apache/struts2/impl/StrutsActionProxy.java
Line number: 69

Stacktraces

java.lang.NullPointerException
    org.apache.struts2.impl.StrutsActionProxy.getErrorMessage(StrutsActionProxy.java:69)
    com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
    org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
    org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
    com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:500)
    org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:434)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
    java.lang.Thread.run(Thread.java:662)
    



You are seeing this page because development mode is enabled. Development mode, or devMode, enables extra debugging behaviors and reports to assist developers. To disable this mode, set:

  struts.devMode=false
in your WEB-INF/classes/struts.properties file.


  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

12条回答