问题描述
- 求助:这个Structs2 登录demo的action始终无法正常工作
-
错误:访问URL http://localhost:8080/Structs2/login.actionHTTP Status 404 - /Structs2/login.action
type Status report
message /Structs2/login.actiondescription The requested resource is not available.
代码:
G:WorkspacesMyEclipseStructs2WebRootlogin.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
username:
password:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">G:WorkspacesMyEclipseStructs2srcstruts.xml
/result.jsp
G:WorkspacesMyEclipseStructs2srccomactionloginLoginAction.java
package com.action.login;public class LoginAction {
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; } /** * 赋值之后会自动执行 * @return * @throws Exception */ public String execute() throws Exception { System.out.println("execute()"); return "success"; }
}
G:WorkspacesMyEclipseStructs2WebRootWEB-INFlibweb.xml
<?xml version="1.0" encoding="UTF-8"?>
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">struts2
org.apache.struts2.dispatcher.FilterDispatcher<filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
跟着网上各种方法都解决不了,但是是跟着浪曦的视频做的,视频里的可以运行,自己的不行,求大神解答
解决方案
把你的错误信息全部出来贴
解决方案二:
action="${ pageContext.request.contextPath }/login.action" 你把表单里面的action换成这个试试。
struts.xml中配置
/login.jsp
解决方案三:
<!--name 对应的是from表单action对应的值 method对应的是action类中的login方法也可以这样 method属性值为一个表达式{1},表示它的值是name属性值中第一个*的值。例如:用户请求URL为user_login.action时,将调用到UserAction类的login方法;用户请求URL为user_regist.action时,将调用到UserAction类的regist方法。class对应spring的配置文件applicationContext.xml用户注册的ACTION的id-->
13. /success.jsp
14. /login.jsp
15.
你的struts有没有对action配置,类似上面的
解决方案四:
/login2.jsp
/result.jsp
解决方案五:
原来是web.xml的位置放错了
解决方案六:
web.xml默认放在web-inf下面