有哪位高手进来看看,在Struts中传参数的问题?
下面是我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中。这是为什么呢?有哪位高手赐教,小弟是新手,望海涵!!!!!
------解决方案--------------------
探讨 引用: 第一种方法是: <form action = "user" method = "post"> 改成 <form action = "User!add.action" method = "post"> <result name="success"> /hello.jsp </result> 第二种方法是: 把这些代码 S……