- 爱易网页
-
Java教程
- 跪求!怎么将jsp中表单的内容提交给Struts2的action处理
日期:2014-05-17 浏览次数:20712 次
跪求高手指点!如何将jsp中表单的内容提交给Struts2的action处理
各位高手们我是这样做的:我在MyJsp.jsp如下
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>My JSP 'MyJsp.jsp' starting page</title>
</head>
<body>
<form method="post" action="Login.action">
<p>name: <input type="text" name="name"></p>
<p>Pwd:<input type="password" name="Pwd">
<input type="submit" name="button1"></form></body>
</html>
Bean如下:package actions;
public class UserBean {
private String name;
private String Pwd
public String getName() {return name;}
public void setName(String name) {this.name = name;}
public String getPwd() {return Pwd;
}
public void setPwd(String pwd) {Pwd = pwd;
}
;
}
action类:
package actions;
import com.opensymphony.xwork2.ActionSupport;
public class Login extends ActionSupport{
private UserBean userBean;
public String excute(){
//setUserBean(userBean);
System.out.println("测试用户名name:"+getUserBean().getName());//但是始终没打印,这就是问题所在
System.out.println("测试密码Pwd:"+getUserBean().getPwd());
return SUCCESS;
}
public UserBean getUserBean() {
return userBean;
}
public void setUserBean(UserBean userBean) {
this.userBean = userBean;
}
}
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">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping></web-app>
Strut.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="Struts" namespace="StrutsPath"
extends="struts-default">
<action name="Login" class="actions.Login">
<result name="success">/SuccessJsp.jsp</result>
</action>
</package></struts>
//跪求各路高手指点了,提交按钮后总是出现404,难道配置有问题吗,我一直很不理解,希望各路高手能给我指点!谢谢了~