跟着传智播客的视频学struts1在MyEclipse中建的目录,导入相关的包,输入http://localhost:8080/strutstest1/这个路径报404错误为什么?我知道他没有在Webroot目录下建index.jsp文件,为什么他的可以出来我的出不来?
strutstest1
----src
-------cn.itcast
------------LoginAction.java
------------LoginForm.java----WebRoot
-------WEB-INF
-----------struts-config.xml
-----------web.xml
-------Login.jsp
-------LoginFailure.jsp
-------LoginSuccess.jspweb.xml文件
 <servlet>
  <servlet-name>action</servlet-name>
  <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
  <init-param>
  <param-name>config</param-name>
  <param-value>/WEB-INF/struts-config.xml</param-value>
  </init-param>
 
  <load-on-startup>0</load-on-startup>
 </servlet> 
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
 
我是不是少了什么东西?

解决方案 »

  1.   

          <welcome-file-list>
    <welcome-file>Login.jsp</welcome-file>
    </welcome-file-list>
      

  2.   

    包包引进来了没?struts-config.xml里的配置也贴一些
      

  3.   

    web.xml配置文件里面可以设置根目录下默认访问页面,如果你想默认访问login.jsp的话
    在配置文件末尾加上一下配置信息就可以了
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
      

  4.   

    在配置文件加<welcome-file-list>
    <welcome-file>Login.jsp</welcome-file>
    </welcome-file-list>
    可以,但是我有不明白为什么他的web.xml什么没有就可以访问这个路径http://localhost:8080/strutstest,而我的却不可以?
      

  5.   

    strutstest后面少了一个1.应该是http://localhost:8080/strutstest1
      

  6.   

    1、没看过你的代码,不知道里面的逻辑咋样。2、你的servlet-mapping里面的url-pattern写得是*.do,为什么你输入的地址是 http://localhost:8080/strutstest1/。应该以*.do结尾吧??
      

  7.   

    我也不明白。他里面的代码是这样写的。
    我是跟着视频里走的谁知刚开始就这样http://dl.dbank.com/c0isp3n365这个网址中的03是我看的视频....
    代码是这样的:
    cn.itcast包中的java文件为:
    LoginAction.java

    package cn.itcast;import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;public class LoginAction extends Action { @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)
    throws Exception {


    LoginForm loginForm = (LoginForm)form;

    if(loginForm.getUsername().equals("itcast")){

    return mapping.findForward("loginSuccess");

    }else{
    return mapping.findForward("loginFailure");
    }

    }
     
    }
    LoginForm.java
    package cn.itcast;import org.apache.struts.action.ActionForm;
    @SuppressWarnings("serial")
    public class LoginForm extends ActionForm {
    private String password;
    private String username;

    public String getPassword() {
    return password;
    }
    public void setPassword(String password) {
    this.password = password;
    }
    public String getUsername() {
    return username;
    }
    public void setUsername(String username) {
    this.username = username;
    }

    }WEB-INF-----
    struts-config.xml<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts-config PUBLIC
              "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
              "http://struts.apache.org/dtds/struts-config_1_3.dtd"><struts-config> <form-beans>
    <form-bean name="loginForm" type="cn.itcast.LoginForm"></form-bean>
    </form-beans>


    <action-mappings>
    <action path="/login" type="cn.itcast.LoginAction" name="loginForm">
    <forward name="loginSuccess" path="/LoginSuccess.jsp"></forward>

    <forward name="loginFailure" path="/LoginFailure.jsp"></forward>
    </action>
    </action-mappings>                                                                                     </struts-config>
    Login.jsp
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
      <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body> <form action="<%=basePath%>login.do" method="post">
    username:<input type="text" name="username"><br>
    password:<input type="password" name="password"><br>
    <input type="submit" value="login"/>
    </form>

    </body>
    </html>LoginFailure.jsp 和LoginSuccess.jsp中分别只写了一句话,作为跳转时的区别。
      

  8.   

    我觉得你的web.xml少了点东西!直接访问项目名会默认index.jsp
    你把
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    删除了就找不到Webroot目录下index.jsp了
    或者加上
    <welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
    </welcome-file-list>
    因为你已经把index.jsp删除了
      

  9.   


    说的对,你按wen157604891说的仔细查看下
      

  10.   

    不是广告贴!!我只是做的时候不明白,再说现在都学的是struts2....