大家好!小弟最近在学习struts2,遇到了一些问题,不好意思又来贴代码麻烦大家啦!我大致按照教科书上的代码敲出来以后报错(另:tomcat 6.0启动正常),如下:
在地址栏中输入:http://localhost:8090/strutstest/login.jsp
浏览器中显示以下信息:HTTP Status 404 - /strutstest/login.jsp--------------------------------------------------------------------------------type Status reportmessage /strutstest/login.jspdescription The requested resource (/strutstest/login.jsp) is not available.
--------------------------------------------------------------------------------Apache Tomcat/6.0.32
这个项目的目标是:显示一个login.jsp页面,用户输入的用户名和密码如果等于"ibit"就跳转到index.jsp页面,否则失败就跳转到error.jsp页面。
项目名:strutstest,
项目里就一个包:org.strutstest.action,里面放一个UserAction类
另外三个页面:index.jsp、error.jsp、login.jsp。下面是我的所有代码:UserActionpackage org.strutstest.action;import com.opensymphony.xwork2.ActionSupport;public class UserAction extends ActionSupport{ private static final long serialVersionUID = 2591244218711682450L;
private String name;
private String password;
public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public String login(){
if(name.equalsIgnoreCase("ibit")&password.equalsIgnoreCase("ibit"))
return SUCCESS;
return ERROR;
}
}
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>
<constant name="struts.devMode" value="true"></constant>
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
<constant name="struts.ui.theme" value="simple"></constant>
<package name="myStruts" namespace="/" extends="struts-default">
<action name="login" class="org.strutstest.action.UserAction" method="login">
<result name="success">/index.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
</struts>
web.xml(部分)<?xml version="1.0" encoding="utf-8"?>
<web-apps>
<filter>
<filter-name>StrutsPrepareAndExecuteFilter</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>StrutsPrepareAndExecuteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-apps>
login.jsp<html>
<head>
<title>login.jsp</title>
</head>
<body>
<s:form action="login">
<s:textfield name="name" label="用户名"/>
<s:password name="password" label="密码"/>
<s:submit value="立即登录"/>
</s:form>
</body>
</html>
下列是我在项目中加入的jar包:
commons-fileupload-1.2.2.jar
commons-io-2.0.1.jar
commons-lang-2.5.jar
freeer-2.3.16.jar
ognl-3.0.1.jar
struts2-core-2.2.3.jar
xwork-core-2.2.3.jar
javassist-3.11.0.GA.jar非常感谢大家耐心看完的代码,谢谢你们!
在地址栏中输入:http://localhost:8090/strutstest/login.jsp
浏览器中显示以下信息:HTTP Status 404 - /strutstest/login.jsp--------------------------------------------------------------------------------type Status reportmessage /strutstest/login.jspdescription The requested resource (/strutstest/login.jsp) is not available.
--------------------------------------------------------------------------------Apache Tomcat/6.0.32
这个项目的目标是:显示一个login.jsp页面,用户输入的用户名和密码如果等于"ibit"就跳转到index.jsp页面,否则失败就跳转到error.jsp页面。
项目名:strutstest,
项目里就一个包:org.strutstest.action,里面放一个UserAction类
另外三个页面:index.jsp、error.jsp、login.jsp。下面是我的所有代码:UserActionpackage org.strutstest.action;import com.opensymphony.xwork2.ActionSupport;public class UserAction extends ActionSupport{ private static final long serialVersionUID = 2591244218711682450L;
private String name;
private String password;
public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public String login(){
if(name.equalsIgnoreCase("ibit")&password.equalsIgnoreCase("ibit"))
return SUCCESS;
return ERROR;
}
}
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>
<constant name="struts.devMode" value="true"></constant>
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
<constant name="struts.ui.theme" value="simple"></constant>
<package name="myStruts" namespace="/" extends="struts-default">
<action name="login" class="org.strutstest.action.UserAction" method="login">
<result name="success">/index.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
</struts>
web.xml(部分)<?xml version="1.0" encoding="utf-8"?>
<web-apps>
<filter>
<filter-name>StrutsPrepareAndExecuteFilter</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>StrutsPrepareAndExecuteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-apps>
login.jsp<html>
<head>
<title>login.jsp</title>
</head>
<body>
<s:form action="login">
<s:textfield name="name" label="用户名"/>
<s:password name="password" label="密码"/>
<s:submit value="立即登录"/>
</s:form>
</body>
</html>
下列是我在项目中加入的jar包:
commons-fileupload-1.2.2.jar
commons-io-2.0.1.jar
commons-lang-2.5.jar
freeer-2.3.16.jar
ognl-3.0.1.jar
struts2-core-2.2.3.jar
xwork-core-2.2.3.jar
javassist-3.11.0.GA.jar非常感谢大家耐心看完的代码,谢谢你们!
<s:textfield name="name" label="用户名"/>
<s:password name="password" label="密码"/>
<s:submit value="立即登录"/>
</s:form>
你要使用这一段代码 login.jsp在struts的配置文件中也要做映射
<web-apps>
<filter>
<filter-name>StrutsFilter</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>StrutsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-apps>
改为
<action name="/login" class="org.strutstest.action.UserAction" method="login">