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>

  • 相关阅读:
    如何选择RabbitMQ的消息保存方式?
    一次Flannel和Docker网络不通定位问题
    flannel
    vsftp设置不同用户登录ftp的根目录不同
    nginx反向代理服务器获取不到端口的问题的解决办法
    RabbitMQ 内存控制 硬盘控制
    -bash: fork: Cannot allocate memory
    redis info
    nginx第三方模块---nginx-sticky-module的使用(基于cookie的会话保持)
    Haproxy的三种保持客户端会话保持方式
  • 原文地址:https://www.cnblogs.com/Qnana/p/5358037.html
Copyright © 2011-2022 走看看