jar包都放进去会产生冲突,放必要的就够了

解决方案 »

  1.   

    是因为struts.xml文件头写错了
    正确写法是:
    <!DOCTYPE struts PUBLIC
              "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
              "http://struts.apache.org/dtds/struts-2.0.dtd">而你写的是:
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
        "system11"
        "struts-2.0.dtd">这个最好直接到官网上下载,直接复制粘贴
      

  2.   

    我就照着教程把几个放进去了,没有把全部jar包放进去
      

  3.   

    我这样改了,也还是不行,还是显示404这里的struts.xml图标也不是一个X的样子
      

  4.   

    哪里有HelloWorld.jsp???你是怎么请求的?
      

  5.   

    上面最后一串代码就是HelloWorld.jsp啊。请求的话在struts.xml里配置了吧?
      

  6.   


    在这里的.xml格式就是这个图标的,
      

  7.   

    我仿照你的代码写了一个:StudentAction.java:
    /**
     * 
     */
    package com.you.action;import com.opensymphony.xwork2.ActionSupport;/**
     * @author Administrator
     *
     */
    public class StudentAction extends ActionSupport 
    {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private String message; @Override
    public String execute() throws Exception 
    {
    if("".equals(message))
    {
    return "error";
    }
    else
    {
    return "success";
    }
    } /**
     * @return the message
     */
    public String getMessage() {
    return message;
    } /**
     * @param message the message to set
     */
    public void setMessage(String message) {
    this.message = message;
    }}
    struts.xml:
    <!--
    /*
     * $Id: struts.xml 1364077 2012-07-21 12:57:02Z lukaszlenart $
     *
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements.  See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership.  The ASF licenses this file
     * to you under the Apache License, Version 2.0 (the
     * "License"); you may not use this file except in compliance
     * with the License.  You may obtain a copy of the License at
     *
     *  http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing,
     * software distributed under the License is distributed on an
     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     * KIND, either express or implied.  See the License for the
     * specific language governing permissions and limitations
     * under the License.
     */
    -->
    <!DOCTYPE struts PUBLIC
              "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
              "http://struts.apache.org/dtds/struts-2.0.dtd">
    <struts>
        <package name="default" extends="struts-default">
            <action name="StudentAction" class="com.you.action.StudentAction">
                <result name="success">student.jsp</result>
                <result name="error">error.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">
      <display-name></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>
      
      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
    </web-app>
    student.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>My JSP 'student.jsp' starting page</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>
        <form id="form1" name="form1" method="post" action="StudentAction.action">
         <p>输入信息:
           <input type="text" name="message" id="username"/>
         </p>
         <p><input type="submit" name="submit" value="提交"></p>
        </form>
      </body>
    </html>error.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>My JSP 'error.jsp' starting page</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>
        This is my JSP page. <br>
      </body>
    </html>
    浏览器地址:http://localhost:8080/struts/student.jsp
    当输入框中输入“you”点击“提交”,会将内容提交;当输入框中的内容为空时,点击提交
    地址栏的地址变为:http://localhost:8080/struts/StudentAction.action
      

  8.   

    //你的HelloWorld类继承ActionSupport了吗?
    public class HelloWorld extends ActionSupport {
    ...............
    }
      

  9.   

    代码就是照着你的代码输进去的,
    StudentAction.java
    package com.you.action;import com.opensymphony.xwork2.ActionSupport;public class StudentAction extends ActionSupport{
    private static final long serialVersionUID=1L;
    private String message;
    public String execute() throws Exception
    {
    if("".equals(message))
    {
    return "error";
    }
    else
    {
    return "success";
    }
    }
    public String getMessage(){
    return message;
    }
    public void setMessage(String message){
    this.message=message;
    }
    }
    struts.xml
    <!--
    /*
     * $Id: struts.xml 1364077 2012-07-21 12:57:02Z lukaszlenart $
     *
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements.  See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership.  The ASF licenses this file
     * to you under the Apache License, Version 2.0 (the
     * "License"); you may not use this file except in compliance
     * with the License.  You may obtain a copy of the License at
     *
     *  http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing,
     * software distributed under the License is distributed on an
     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     * KIND, either express or implied.  See the License for the
     * specific language governing permissions and limitations
     * under the License.
     */
    -->
    <!DOCTYPE struts PUBLIC
              "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
              "http://struts.apache.org/dtds/struts-2.0.dtd">
    <struts>
        <package name="default" extends="struts-default">
            <action name="StudentAction" class="com.you.action.StudentAction">
                <result name="success">student.jsp</result>
                <result name="error">error.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">
      <display-name></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>
      
      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
    </web-app>
    student.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>My JSP 'student.jsp' starting page</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>
        <form id="form1" name="form1" method="post" action="StudentAction.action">
         <p>输入信息:
           <input type="text" name="message" id="username"/>
         </p>
         <p><input type="submit" name="submit" value="提交"></p>
        </form>
      </body>
    </html>
    error.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>My JSP 'error.jsp' starting page</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>
        This is my JSP page. <br>
      </body>
    </html>
      

  10.   


    这里改成这样试试 <result name="success">/student.jsp</result>
                                     <result name="error">/error.jsp</result>
      

  11.   

    应用的上下文配置了么?右键应用 properties 在里面看看?或者双击tomcat server 点击modules 查看
      

  12.   

    struts.xml配置文件放错位置了,放在src下面 或者在web.xml下配置struts.xml位置
      

  13.   


    这里改成这样试试 <result name="success">/student.jsp</result>
                                     <result name="error">/error.jsp</result>
    也不行额
      

  14.   

    错了  在src下放src下好像也不行
      

  15.   

    我看了下。你strut里配置的success是success.jsp..而你的项目里没有这个页面吧。你那个改成你要跳转的页面就好了。
      

  16.   

    错了  在src下放src下好像也不行项目发给我看下
      

  17.   

    错了  在src下放src下好像也不行项目发给我看下留个QQ?还是?
      

  18.   

    楼主你的tomact的server.xml后面加上 <Context docBase="MyWebPage" path="/MyWebPage" reloadable="true" source="org.eclipse.jst.jee.server:项目名称"/>
      

  19.   

    开debug调试,看能不能进行action后台
      

  20.   

    错了  在src下放src下好像也不行项目发给我看下留个QQ?还是?
    [email protected] 发邮箱吧