我就想试下JSP表单隐藏传属性到后台,可我设的这个变量 p 传过去action那打印出来是“空值”,当我传的是常量的时候是没有问题的,我想请教下这个变量问题出在那!谢谢JSP页面代码如下:<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@ taglib prefix="s" uri="/struts-tags"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>注册页</title> </head> <%! String p="1581458541"; %> <body> <center> <s:form action="zhucechenggong.action" method="post"> <s:textfield name="user.name" label="账户名"></s:textfield> <s:password name="user.password" label="密码"></s:password> <s:hidden name="user.phone" value="%{p}"></s:hidden> <s:submit value="注册"></s:submit> </s:form> </center> </body></html>跳转到java的action代码如下:package com.action;import com.opensymphony.xwork2.ActionSupport;import com.user.User;import com.server.*;@SuppressWarnings("serial")public class ZhuCeAction extends ActionSupport { private User user; private UserServer userServer; public void setUserServer(UserServer userServer) { this.userServer = userServer; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } public String execute()throws Exception{ userServer.save(user); System.out.println(user.getPhone()); return SUCCESS; }}
1 回答
黑女2008
TA贡献75条经验 获得超32个赞
value是input默认属性,好像不能接收表达式,可以这样写
<s:hidden name="user.phone" value="" a="<%= p %>"></s:hidden>
自己声明个属性,但是这样还不如,js,在提交的时候给你的phone赋值。
添加回答
举报
0/150
提交
取消