前端代码演示
| <%--前端带上参数请求struts.xml配置文件中的hello--%> |
| <%@ page contentType="text/html;charset=UTF-8" language="java" %> |
| <%@taglib prefix="s" uri="/struts-tags" %> |
| <html> |
| <head> |
| <title>index</title> |
| <%@include file="./common.jsp"%> |
| </head> |
| <body> |
| |
| <form class="layui-form" action="hello" method="post"> |
| <div class="layui-form-item" style="margin: 10px"> |
| <div class="layui-inline"> |
| <label class="layui-form-label">用户名:</label> |
| <div class="layui-input-inline" style="width: 200px;"> |
| <input id="ename" type="text" name="user.userId" placeholder=" 请输入用户名" autocomplete="off" class="layui-input"> |
| </div> |
| <label class="layui-form-label">编号:</label> |
| <div class="layui-input-inline" style="width: 200px;"> |
| <input id="empno" type="text" name="user.userName" placeholder=" 请输入编号" autocomplete="off" class="layui-input"> |
| </div> |
| <div class="layui-input-inline" style="width: 100px;"> |
| <button type="submit" class="layui-btn layui-btn-normal"><i class="layui-icon layui-icon-search"></i> 刷新</button> |
| </div> |
| </div> |
| </div> |
| </form> |
| |
| <a href="${path}/form.jsp">添加</a> |
| |
| <table class="layui-table" lay-filter="empInfo"> |
| <thead> |
| <tr> |
| <th><input type="checkbox"></th> |
| <th>编号</th> |
| <th>姓名</th> |
| <th>年龄</th> |
| <th>性别</th> |
| <th>省份</th> |
| <th>大区</th> |
| <th>小组信息</th> |
| <th>操作</th> |
| </tr> |
| <s:iterator value="#roleList"> |
| <tr> |
| <!-- 值栈方式接收 --> |
| <td><input type="checkbox"></td> |
| <td><s:property value="empno"/></td> |
| <td><s:property value="ename"/></td> |
| <td><s:property value="age"/></td> |
| <td><s:property value="sex"/></td> |
| <td><s:property value="province"/></td> |
| <td><s:property value="deptld==1?'北京':'南京'"/></td> |
| <td><s:property value="groupu"/></td> |
| <td><a href="#">删除</a></td> |
| </tr> |
| </s:iterator> |
| </table> |
| </body> |
| </html> |
配置代码演示
| |
| <?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.i18n.encoding" value="utf-8"></constant> |
| |
| |
| <package name="default" extends="struts-default"> |
| |
| |
| |
| |
| <action name="hello" class="com.struts.HelloAction"> |
| |
| <result name="success">/index.jsp</result> |
| |
| </action> |
| |
| <action name="world" class="com.struts.WorldAction"> |
| <result name="success">/form.jsp</result> |
| </action> |
| |
| |
| |
| |
| </package> |
| </struts> |
后端代码演示
| |
| package com.struts; |
| |
| import cn.hutool.http.HttpRequest; |
| import com.alibaba.fastjson.JSON; |
| import com.alibaba.fastjson.JSONObject; |
| import com.opensymphony.xwork2.Action; |
| import com.opensymphony.xwork2.ActionContext; |
| import com.struts.outer.Result; |
| import com.struts.outer.Staff; |
| import com.struts.outer.User; |
| import com.struts.outer.Week; |
| |
| import java.util.ArrayList; |
| import java.util.Collections; |
| import java.util.List; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public class HelloAction implements Action { |
| |
| private String name; |
| private String message; |
| private User user; |
| |
| @Override |
| public String execute() throws Exception { |
| |
| |
| |
| |
| |
| |
| String json = "{\"page\": 1,\"limit\": 10}"; |
| String body = HttpRequest.post(Week.URL + "/staff/list").timeout(2000) |
| |
| .body(json) |
| .execute() |
| .body(); |
| JSONObject obj = (JSONObject)JSON.parse(body); |
| if(obj != null){ |
| List<Staff> userList = JSON.parseArray(obj.getString("data"), Staff.class); |
| String resCode = obj.getString("count"); |
| |
| System.out.println(resCode); |
| List<Result> list = new ArrayList<>(); |
| Result result = new Result(obj.getString("msg"), Integer.parseInt(obj.getString("code")), userList, Integer.parseInt(obj.getString("count"))); |
| Collections.addAll(list,result); |
| ActionContext.getContext().put("roleList", list.get(0).getData()); |
| } |
| |
| return SUCCESS; |
| } |
| |
| public String getName() { |
| return name; |
| } |
| |
| public void setName(String name) { |
| this.name = name; |
| } |
| |
| public String getMessage() { |
| return message; |
| } |
| |
| public void setMessage(String message) { |
| this.message = message; |
| } |
| |
| public User getUser() { |
| return user; |
| } |
| |
| public void setUser(User user) { |
| this.user = user; |
| } |
| } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~