今天试着搭建struts框架,但是却总是无法访问,求兄弟姐妹们帮忙...
配置文件和struts包都是按教科书上配置的,struts的版本是struts-2.1.8.1,复制到项目上的struts类为:
commons-fileupload-1.2.1.jar,commons-logging-1.0.4.jar,freemarker-2.3.15.jar,
ognl-2.7.3.jar,struts2-core-2.1.8.1.jar,xwork-core-2.1.6.jar
具体情况是:
项目名:struts_login
action:
com.loginAction package com; import com.opensymphony.xwork2.ActionSupport; public class loginAction extends ActionSupport { private String loginname; private String pwd; public String getLoginname() { return loginname; } public void setLoginname(String loginname) { this.loginname = loginname; } public String getPwd() { return pwd; } public void setPwd(String pwd) { this.pwd = pwd; } public String checkLogin() { if(this.loginname.equals("admin")&&this.pwd.equals("admin")) return SUCCESS; else return LOGIN; } }
jsp页面:
index.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"> <html> <head> <base href="<%=basePath%>"> <title>登录成功</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <center> <h2>登录成功,这里是系统后台</h2> </center> </body> </html>
login.jsp <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <%@ taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>用户登录</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <center> <br/> <s:form action="checkLogin" namespace="/login"> <s:textfield name="loginname" label="登录名称"></s:textfield> <s:textfield name="pwd" label="登录密码"></s:textfield> <s:submit value="登录"></s:submit> </s:form> </center> </body> </html>
配置文件:
web.xml <?xml version="1.0" encoding="UTF-8" ?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <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 <?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> <include file="struts-default.xml"></include> <package name="Struts 2.0_login" extends="struts-default" namespace="/login"> <action name="checkLogin" class="com.loginAction" method="checkLogin"> <result name="success">/index.jsp</result> <result name="login">/login.jsp</result> </action> </package> </struts>
当我试着用:http://localhost:8080/struts_login访问时,出来的总是经典的404...
大神们,求解决啊...