您的位置:首页 > 编程语言 > Java开发

Struts2接收请求参数

2015-06-10 22:52 459 查看
     HelloWorldAction.java
public class HelloWorldAction {
private Integer id;
private String name;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String work() {
return "success";
}

public String execute() throws Exception {
return "success";
}
}


     struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<constant name="struts.action.extension" value="do,action" />

<package name="he" namespace="/hello" extends="struts-default">
<action name="h1_*" class="com.zero.HelloWorldAction" method="{1}">
<result name="success">/WEB-INF/jsp/hello.jsp</result>
</action>
</package>
</struts>


     hello.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'hello.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>
id=${id }
<br/>
name=${name }
</html>
访问:http://localhost:8080/Struts2/hello/h1_execute.do?id=11&name=zzzz

          或

          http://localhost:8080/Struts2/hello/h1_work.action?id=11&name=zzzz
          能得到浏览器显示:
id=11
name=zzzz
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: