我就想试下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;
}
}
黑女2008
相关分类