我有一個包含用戶信息的數據庫。當用戶登錄時,我註冊的用戶的會話如下:使用OGNL自定義struts2文本字段標記的值
ActionContext.getContext().getSession().put("loggedUser", user);
我想獲得用戶的信息在我的jsp頁面用這個信息來填充Struts2的文本字段。我試着用下面的代碼,但它不工作:
<%@page import="java.util.Map"%>
<%@page import="com.opensymphony.xwork2.ActionContext"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="UbiMail.*" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%
User user = (User) ActionContext.getContext().getSession().get("LoggedUser");
%>
<html>
<head>
</head>
<body>
<s:form method="POST" action="UpdateAction">
<s:actionerror/>
<s:textfield name="uname" label="Username" value="#session.LoggedUser.getUsername"/>
<s:property value="#session.LoggedUser.getUsername()"/>
<s:password name="password" label="Password"/>
<s:password name="cPassword" label="Confirm password"/>
<s:textfield name="fname" label="First name" value="#session.loggeduser.getFname()"/>
<s:textfield name="lname" label="Last name" value="#session.loggeduser.getLname()"/>
<s:textfield name="popServer" label="POP server" value="#session.loggeduser.getPopServer()"/>
<s:textfield name="popUsername" label="POP username" value="#session.loggeduser.getPopUsername()"/>
<s:password name="popPassword" label="POP password"/>
<s:textfield name="mobilePhone" label="Mobile phone" value="#session.loggeduser.getMobilePhone()"/>
<s:textfield name="filter" label="Notification filter" value="#session.loggeduser.getSms()"/>
<s:checkbox name="sms" label="Enable SMS notification"/>
<s:submit value="Update"/>
</s:form>
</body>
我想你的幫助,謝謝。
是的,它是工作,非常感謝你mprabhat :) – SSMZ
高興你得到它的工作 – mprabhat