下面是我index.jsp文件中的内容
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
   <!-- <META HTTP-EQUIV="Refresh" CONTENT="0;URL=example/HelloWorld.action">-->
</head><body>
<form action = "user" method = "post">
姓名:<input type = "text" name = "name"/>
年龄:<input type = "text" name = "age"/>
<input type = "submit" value = "submit">
</form>
</body>
</html>
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><package name="user" namespace="/" extends="struts-default">
  <action name="user" class = "org.com.User">
            <result>
                /hello.jsp
            </result>
        </action>
</package>
</struts>User.java的程序:package org.com;
import com.opensymphony.xwork2.ActionSupport;
public class User extends ActionSupport
{ private int age;
private String name; public void setAge()
{ this.age = age;
}
public void setName(){
this.name = name;
}
public int getAge(){
return age;
}
public String getName(){
return name;
} public String add(){
System.out.println("age = " + age);
System.out.println("name = " + name);
return "success";
} public String delete(){
return "success";
}
}hello.jsp的代码
<html>
<head>
    <title>hello</title>
   
</head>
<body>
<h1>1111111111111111111111<h1>
</body>
</html>正常情况下,打开index.jsp文件,输入“姓名”和“年龄”后,Tomcat在后面会输出“neme=姓名”和“age=年龄”,才会跳转到hello.jsp页面中。但我做了好几次,Tomcat就不输出,直接跳转到了hello.jsp中。这是为什么呢?有哪位高手赐教,小弟是新手,望海涵!!!!!

解决方案 »

  1.   

    你在什么地方指定他走的是add 这个方法呢? 你没有指定他就会走ActionSupport的默认的方法吧 
    好久不做web了 记不太清具体是啥了
      

  2.   

    你的提交方法是“post” 当然不会把信息显示在浏览器上表单的Action 改为 “get” 或者不写,传参数就会出现在地址栏,嘿嘿
      

  3.   

    打错了 是 表单的method
      

  4.   


    我把index.jsp文件中的内容
    <form action = "user" method = "post">
    改成“<form action = "user!" method = "post">”
    Tomcat也不会在后面打印出来提交的name 和 age啊!!!
      

  5.   

    表单的提交路径actiong  应该是“/user”吧,
      

  6.   

    <action name="user" method="add" class="org.com.User">
    <result name="success">/hello.jsp</result>
    </action>
    你得找个好点的例子照着写 struts2很多例子
      

  7.   

    第一种方法是:
    <form action = "user" method = "post">
     改成<form action = "User!add.action" method = "post">
     <result name="success">
       /hello.jsp
       </result> 第二种方法是:
    把这些代码
    System.out.println("age = " + age);
     System.out.println("name = " + name);
     return "success";
    Action的默认方法中,
    也就是
    public String execute()throws Exception{
    System.out.println("age = " + age);
     System.out.println("name = " + name);
     return "success";}
     
      

  8.   


    我试了,如果是“/user"就会出现“The requested resource (/user!add) is not available.
    ”错误!!
      

  9.   

    +1 另外struts2很多例子 程序的 你自己写的太不规范了 你看一下struts2官方的sample就比你自己的好
      

  10.   


    我试了,
    第一种方法得到:
    There is no Action mapped for namespace [/] and action name [User] associated
    的错误。第二种方法得到:
    age = 0
    name = null
      

  11.   

    你不觉得你得set方法很诡异么
    public void setAge()
    { this.age = age;
    }
    public void setName(){
    this.name = name;
    }
    你都把它设成空了 打印出来当然是那个结果 
    应该
    public void setAge(int age)
    { this.age = age;
    }
      

  12.   

    是,是这样的!!!高手果然是高手 !小弟佩服!!!!以前老是用eclipse自动生成set、get方法。现在用手写,居然写错了!!!
    工具害死人了。
    我也太马虎了!!!多谢大哥提点!!!
      

  13.   

    [Quote=引用 14 楼 zhoujiaolongde 的回复:]
    引用 13 楼 hfei99999 的回复:
    你不觉得你得set方法很诡异么
    public void setAge()
    { this.age = age;
    }
    public void setName(){
    this.name = name;
    }
    你都把它设成空了 打印出来当然是那个结果  
    应该
    public void setAge(int age)
    { this.age = age;
    }
    是,是这样的!!!高手果然是高手 !小弟佩服!!!!以前老是用eclipse自动生成set、get方法。现在用手写,居然写错了!!!
    工具害死人了。
    我也太马虎了!!!多谢大哥提点!!!