使用action屬性接收參數

package com.bjsxt.struts2.user.action;html

import com.opensymphony.xwork2.ActionSupport;java

public class UserAction extends ActionSupport {
 
 private String name;
 private int age;
 
 public String add() {
  System.out.println("name=" + name);
  System.out.println("age=" + age);
  return SUCCESS;
 }apache

 public String getName() {
  return name;
 }jsp

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

 public int getAge() {
  return age;
 }this

 public void setAge(int age) {
  this.age = age;
 }
 
 
}spa

 

 

 

<?xml version="1.0" encoding="GB18030" ?>
<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>xml

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>htm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030" />
<base href="<%=basePath %>"/>
<title>Insert title here</title>
</head>
<body>
使用action屬性接收參數<a href="user/user!add?name=a&age=8">添加用戶</a>
 
</body>
</html>jsx

 

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030" />
<title>Insert title here</title>
</head>
<body>
 User Add Success!
</body>
</html>

 

 

 

<?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>    <constant name="struts.devMode" value="true" />    <package name="user" extends="struts-default" namespace="/user">                <action name="user" class="com.bjsxt.struts2.user.action.UserAction">            <result>/user_add_success.jsp</result>        </action>    </package></struts>

相關文章
相關標籤/搜索