Struts2接收请求参数

来源:互联网 发布:如何评价新东方 知乎 编辑:程序博客网 时间:2024/05/01 06:52
     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

0 0