zoukankan      html  css  js  c++  java
  • 学习使用action属性来接受参数

    1、在配置java jdk的版本。属性中去配置, java compier 里的版本。

    2、去创建useraction。

    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;
    }

    public String getName() {
    return name;
    }

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

    public int getAge() {
    return age;
    }

    public void setAge(int age) {
    this.age = age;
    }
    3、跟上次学习的一样要去配置struts,

    <?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>

    4、webroot

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

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

    <!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>

    在这里我们使用是去如何使用action的属性去接受参数。

    5、在这里显示用户添加成功。

    <?xml version="1.0" encoding="GB18030" ?>
    <%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
    <%@taglib uri="/struts-tags" prefix="s" %>
    <!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>
    添加用户成功!哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈!!!!!!!!!!!!!!!!!!!
    </body>
    </html>

  • 相关阅读:
    [概述]移动机器人自主探索
    MRPT编译
    Kinect2.0相机标定
    小豆包的学习之旅:里程计运动模型
    小豆包的学习之旅:入门篇
    Kinect2.0点云数据获取
    COFF,amd64.vc90.mfc两个布署的问题
    [硬件]Robot运动控制
    [硬件]Urg_viewer数据读取
    [硬件]三维点云数据获取
  • 原文地址:https://www.cnblogs.com/Qnana/p/5358037.html
Copyright © 2011-2022 走看看