The requested resource (/demo1/login/checkLogin/) is not available. 求解答404错误
<web-app>
<display-name>first Struts 2 Project</display-name>
<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>
</web-app>
struts.xml
<struts>
<include file="struts-default.xml"/>
<package name="struts2_login" extends="struts-default" namespace="/login">
<action name="checkLogin" class="act.LoginAction" method="checkLogin">
<result name="success">/index.jsp</result>
<result name="login">/login.jsp</result>
</action>
</package>
</struts>
login.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %> <!—导入Struts 2标签库-->
<style type="text/css">*{font-size:12px;}</style>
<html><body>
<div style=" margin:30px 50px 20px 50px; text-align:center">
<div style="font-size:14px; font-weight:bold">用户登录</div>
<div>
<s:form action="checkLogin" namespace="/login">
<s:textfield name="username" style="font-size:12px; width:120px;" label="登录名称" />
<s:password name="password" style="font-size:12px; width:120px;" label="登录密码" />
<s:submit value=" 登 录 " />
</s:form>
</div>
</div>
</body></html>
代码如上 该怎么访问它?路径怎么写? 展开
struts.xml应该这么写:
<?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">//这块必须写,要不然程序不知道是struts配置文件。不明白楼主为什么还要include一个struts-default.xml,你下面的package已经extends一个了。
<struts>
<package name="struts2_login" extends="struts-default" namespace="/">
<action name="checkLogin" class="act.LoginAction" method="checkLogin">
<result name="success">/index.jsp</result>
<result name="login">/login.jsp</result>
</action>
</package>
</struts>
action方法:
package act;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport{
@SuppressWarnings("unused")
public String checkLogin(){//方法必须为public的
System.out.println("asdad");
return SUCCESS;
}
}
刚才我运行了,成功,没有任何问题