//-------------------
loginAction.java
package com.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;
}
public String execute(){
return SUCCESS;
}
}
//--------------------
login.jsp
<%@ page language="java" contentType="text/html" pageEncoding="GBK"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<s:form action="login">
<s:textfield name="username" label="username"></s:textfield>
<s:password name="password" label="password"></s:password>
<s:submit label="submit"></s:submit>
</s:form>
</body>
</html>
//--------------------------------------
result.jsp
<%@ page language="java" contentType="text/html" pageEncoding="GBK"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
username:${requestScope.username}
<br>
password:${requestScope.password}
</body>
</html>
//---------------------------------
struts.xml
<?xml version="1.0" encoding="GBK" ?>
<!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.action.loginAction">
<result name="SUCCESS">/result.jsp</result>
</action>
</package>
</struts>
//-----------------------------------
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>
//----------------------------------
是从网上摘抄的例子,运行环境是win7 64位 MyEclipse8.5 tomcat7.0 jdk6.0
现在是输入用户名+密码点提交后就报错:
网页报错:
HTTP Status 404 - /struts2/logon.jsp
--------------------------------------------------------------------------------
type Status report
message /struts2/logon.jsp
description The requested resource (/struts2/logon.jsp) is not available.