<s:hidden name="url" value="https://www.tw511.com" />
<input type="hidden" name="url" value="https://www.tw511.com" />
HiddenAction.java
package com.tw511.common.action; import com.opensymphony.xwork2.ActionSupport; public class HiddenAction extends ActionSupport{ private String url; public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } public String execute() { return SUCCESS; } }
hidden.jsp
<%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> </head> <body> <h1>Struts 2 - 隱藏值欄位</h1> <s:form action="helloHidden" namespace="/"> <h2>This page has a hidden value (view source): <s:hidden name="url" value="https://www.tw511.com" /></h2> <s:submit value="submit" name="submit" /> </s:form> </body> </html>
welcome.jsp
<%@ page contentType="text/html;charset=UTF-8" %> <%@ taglib prefix="s" uri="/struts-tags" %> <html> <body> <h1>Struts 2 - 隱藏值欄位</h1> <h2> The hidden value : <s:property value="url"/> </h2> </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="" namespace="/" extends="struts-default"> <action name="hidden"> <result>/pages/hidden.jsp</result> </action> <action name="helloHidden" class="com.tw511.common.action.HiddenAction"> <result name="success">/pages/welcome.jsp</result> </action> </package> </struts>
http://localhost:8080/struts2hidden/hidden.action