1

これらは私が使用しているjarファイルです:

commons-fileupload-1.2.2.jar
commons-io-2.0.1.jar
commons-lang3-3.1.jar
commons-logging-1.1.1.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.8.jar
struts2-dojo-plugin-2.3.8.jar
xwork-core-2.3.8.jar

struts.xml - プロジェクトの Web コンテンツ フォルダーにあります。

<!DOCTYPE struts PUBLIC
 "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
  "http://struts.apache.org/dtds/struts-2.0.dtd">
 <struts>
    <package name="Login" extends="struts-default">
        <action name="login" class="org.jolly.struts.action.LoginAction">
                <result name="SUCCESS">register.jsp</result>
                <result name="LOGIN">login.jsp</result>
        </action>
    </package>

    <package name="Register" extends="struts-default">
        <action name="register" class="org.jolly.struts.action.FormAction">
                <result name="SUCCESS">success.jsp</result>

        </action>
    </package>

web.xml - Web コンテンツ フォルダーに存在

<?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"  
 xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
 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>RegisterForm</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>login.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-name>struts2</filter-name>
<filter-class>
            org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>

<filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
</filter-mapping>

アクション クラス

LoginAction.java

package org.jolly.action;

 import org.apache.commons.lang3.StringUtils;

 import com.opensymphony.xwork2.ActionSupport;

 public class LoginAction extends ActionSupport{

private String userId;
private String password;

public String execute(){
    if(getUserId().equals("user") && getPassword().equals("password"))
        return SUCCESS;
    else
        return LOGIN ;

}

public String getUserId() {
    return userId;
}

public void setUserId(String userId) {
    this.userId = userId;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public void validate(){

    if(StringUtils.isEmpty(getUserId())) {
        addFieldError("userId","UserId cannot be blank");
    }

    if(StringUtils.isEmpty(getPassword())) {
        addFieldError("password","Password cannot be blank");
    }
}

}

FormAction.java

package org.jolly.action;

  import org.apache.commons.lang3.StringUtils;
  import com.opensymphony.xwork2.ActionSupport;

  public class FormAction extends ActionSupport{

private String name;
private String emailId;

public String execute(){
    return SUCCESS;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getEmailId() {
    return emailId;
}

public void setEmailId(String emailId) {
    this.emailId = emailId;
}

   public void validate(){
    if(StringUtils.isEmpty(getName())) {
        addFieldError("name","Name cannot be blank");
    }

    if(StringUtils.isEmpty(getEmailId())) {
        addFieldError("emailid","Email Id cannot be blank");
    }
}

JSPの

1.ログイン.jsp

  <%@ taglib prefix="s" uri="/struts-tags"%> 

<html>
<body>
<s:form action="login">
      <s:textfield label="User Id" key="userid"/>
      <s:password label="Password" key="password"/>
</s:form>
</body>
</html>

2.Register.jsp

    <%@ taglib prefix="s" uri="/struts-tags"%>
    <%@ taglib prefix="sx" uri="/struts-dojo-tags"%>

     <html>
     <head>
      <s:head/>
      <sx:head/>
     </head>
     <body>
     <s:form action="register">
     <s:textfield label="Enter Your Name" key="name"/>
     <s:textfield label="Enter Your Email Id" key="emailId"/>
     <s:checkbox name= "Gender" fieldvalue="Female" value="true"/>
     <s:checkbox name ="Gender" fieldvalue="Male"/>
     <s:checkbox name ="Gender" fieldvalue="Others"/>
     <sx:autocompleter label= "Country" list ="{'India','Pakistan','U.S'}"/>
     <s:textarea key="add" name="address"/>
     <sx:datetimepicker name="date" label="Date" displayFormat="dd/MM/yyyy"/>
    <s:submit value= "Submit Form"/>
 </s:form>
  </body>

3.Success.jsp

  <html>
  <body>
   Form is submitted successfully!!
 </body>
  </html>

エラー

SEVERE: Dispatcher initialization failed
 Unable to load configuration. - action - 

 file:/C:/Users/JOLLY/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpweba 
 pps/RegisterForm%20(1)/WEB-INF/classes/struts.xml:7:69
    at  
 com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager. 
 java:70)
    at 
 org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:429)
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:471)
    at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:193)
    at 
 org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:2
 81)
    at 
 org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:26
 2)
    at org.apache.catalina.core.ApplicationFilterConfig.<init>
 (ApplicationFilterConfig.java:107)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4656)
    at 
 org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5312)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    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: Action class [org.jolly.struts.action.LoginAction] not found - action -  
 file:/C:/Users/JOLLY/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpweba
 pps/RegisterForm%20(1)/WEB-INF/classes/struts.xml:7:69
    at 
 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigur
 ationProvider.java:480)
    at 
 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurati
 onProvider.java:424)
    at 
 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurat
 ionProvider.java:541)
    at c

 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigur
 ationProvider.java:290)
    at 
 org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurati
 onProvider.java:112)
    at 
 com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfigurat
 ion.java:239)
    at 
 com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.
 java:67)
    ... 16 more
    Feb 27, 2013 12:12:12 PM org.apache.catalina.core.StandardContext filterStart

 SEVERE: Exception starting filter struts2

 Unable to load configuration. - action - 
 file:/C:/Users/JOLLY/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpweba
 pps/RegisterForm%20(1)/WEB-INF/classes/struts.xml:7:69
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:483)
    at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:193)
    at 
 org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:2 81)
    at 
 org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:26 
 2)
    at org.apache.catalina.core.ApplicationFilterConfig.<init> 
 (ApplicationFilterConfig.java:107)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4656)
    at 

 org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5312)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    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:/C:/Users/JOLLY/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpweba
 pps/RegisterForm%20(1)/WEB-INF/classes/struts.xml:7:69
    at 
 com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.
 java:70)
    at 
 org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:429)
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:471)
    ... 14 more

 Caused by: Action class [org.jolly.struts.action.LoginAction] not found - action - 
 file:/C:/Users/JOLLY/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpweba
 pps/RegisterForm%20(1)/WEB-INF/classes/struts.xml:7:69
    at 
 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigur
 ationProvider.java:480)
    at 
 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurati
 onProvider.java:424)
    at 
 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurat
 ionProvider.java:541)
    at 
 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigur
 ationProvider.java:290)
    at 
 org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurati
 onProvider.java:112)
    at 
 com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfigurat
 ion.java:239)
    at 
 com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.
 java:67)
    ... 16 more

     Feb 27, 2013 12:12:12 PM org.apache.catalina.core.StandardContext startInternal
     SEVERE: Error filterStart
     Feb 27, 2013 12:12:12 PM org.apache.catalina.core.StandardContext startInternal
     SEVERE: Context [/RegisterForm_(1)] startup failed due to previous errors
     Feb 27, 2013 12:12:12 PM org.apache.coyote.AbstractProtocol start
     INFO: Starting ProtocolHandler ["http-bio-8080"]
     Feb 27, 2013 12:12:12 PM org.apache.coyote.AbstractProtocol start
     INFO: Starting ProtocolHandler ["ajp-bio-8009"]
     Feb 27, 2013 12:12:13 PM org.apache.catalina.startup.Catalina start
     INFO: Server startup in 9975 ms

誰でも助けてください。私は2週間からこれを試しています。

4

2 に答える 2

0

エラーメッセージは、何が問題なのかを正確に示しています。

構成ファイルはアクション クラスに 1 つのパッケージを使用し、アクション クラスは別のパッケージに使用されます。

次の問題は、構成ファイルがすべて大文字の結果名を使用しているのに対し、定数値はすべて小文字であるため、結果が見つからないことです。

古いフィルターも使用しています。また、検証ロジックが重複しているのはなぜですか?

于 2013-02-27T12:24:11.057 に答える