请求的资源(/ Struts1Lab4 /)不可用

时间:2014-07-22 10:40:05

标签: struts-1

HTTP状态404 - / Struts1Lab4 /

输入状态报告

message / Struts1Lab4 /

description请求的资源(/ Struts1Lab4 /)不可用。

Apache Tomcat / 7.0.28

我在tomcat上运行时遇到此错误。我已经添加了所有必需的jar文件。所有其他实验室工作正常,但当我使用验证框架验证时,得到此错误。请帮帮我。

这是我的验证文件 - myform-validations.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts onfiguration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<form-validation>
<formset>

<form name="loginForm">
<field property="username" depends="required,minlength,maxlength">
<arg0 key="un.login" resource="true"/>
<arg1 key="${var:minlength}" resource="false"/>
<arg2 key="${var:maxlength}" resource="false"/>
<var>
<var-name>minlength</var-name>
<var-value>5</var-value>
</var>
<var>
<var-name>maxlength</var-name>
<varvalue>10</varvalue>
</var>
</field>
<field property="password" depends="required,minLimit,maxLimit">
<arg0 key="password" resource="false"/>
<arg1 name="minLimit" key="var:minlength" resource="false"/>
<arg1 name="maxLimit" key="var:maxlength" resource="false"/>
<var>
<var-name>minlength</var-name>
<var-value>6</var-value>
</var>
<var>
<var-name>maxlength</var-name>
<var-value>12</var-value>
</var>
</field>

</form>
</formset>
</form-validation>

这是我的配置文件-struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

<struts-config>
<form-beans>
<form-bean name="loginForm" type="com.jlc.struts.LoginForm"></form-bean>
</form-beans>

<action-mappings>
<action path="/loginSubmit" name="loginForm" type="com.jlc.struts.LoginAction" scope="session" input="/login.jsp">
<forward name="success" path="/home.jsp"/>
<forward name="failed" path="/login.jsp"/>
</action>

</action-mappings>
<message-resources parameter="com.jlc.struts.messages"/>

<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/myform-validations.xml,/WEB-INF/validator-rules.xml"/>

</plug-in>

</struts-config>

这是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" 
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_2_5.xsd"
id="WebApp_ID" version="2.5">

<display-name>Struts1Lab4</display-name>

<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>

</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

</web-app>

这是login.jsp

<html:errors property="login.Invalid"/>

<html:form action="/loginSubmit">
<table>
<tr><td>Username</td>
<td><html:text property="username"/></td>
<td><html:errors property="username"/></td></tr>
<tr><td>Password</td>
<td><html:password property="password"/></td>
<td><html:errors property="password"/></td></tr>
<tr><td><html:submit value="Login Now"/></td></tr>
</table>
</html:form>

这是LoginForm.java

package com.jlc.struts;


import org.apache.struts.validator.ValidatorForm;

public class LoginForm extends ValidatorForm{

private static final long serialVersionUID = 1L;
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;
}
}

1 个答案:

答案 0 :(得分:0)

验证配置文件不使用Struts配置DTD,而是:

<!DOCTYPE form-validation PUBLIC
    "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN"
    "http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">

当然,请使用您的Struts 1版本的实际版本。


不相关,但请缩进您的XML,JSP,Java等。如果没有它,请尝试阅读它是荒谬的。