java - Struts JSP/html inserting current date -
java - Struts JSP/html inserting current date -
this question has reply here:
showing current date using jstl formatdate tag 2 answersmy question simular one: is possible access struts2 variable in jsp scriptlet?
in .jsp page have form in preset text field current date. issue "value" not back upwards runtime expressions when using struts - makes sense want maintain much java out of jsp possible. leaves me struggling variable out of action. running on tomcat v7.0 , eclipse java ee ide web developers. version: kepler service release 2.
in .jsp page have:
<s:set var="currentdate" value="currentdate"/> <s:property value="currentdate"/> <s:form action= "updateaction"> <s:textfield name="dateupdated" key="label.dateupdated" size="20" value="%{currentdate}" /> <s:submit method="execute" key="submit"/> </s:form>
now have 3 actions - 1 page(topageaction), 1 when form submitted(updateaction), 1 gets currentdate variable(getcurrentdateaction).
i think going crazy >.<
anyways, action currentdate variable called getcurrentdateaction , looks like:
public class getcurrentdateaction extends actionsupport { simpledateformat date = new simpledateformat("yyyy-mm-dd hh:mm:ss"); public string currentdate = date.tostring(); public string getcurrentdate(){ homecoming currentdate; } public void setvariable(string currentdate){ this.currentdate=currentdate; } public string execute() throws exception{ homecoming success; } }
additionally in struts.xml have:
<action name="getcurrentdateaction" class="net.upsmon.struts2.action.getcurrentdateaction"> <result name="success">alertpersistencyview.jsp</result> </action>
i have read through question linked many, many times , tried format own struts correctly find myself getting lost. not sure if answers misleading or not understanding sense issue cannot hard solve. in .jsp page have property tag prove myself got variable .jsp has not yet worked. , additionally textfield blank. advice out there me variable .jsp? there additional info can provide solution? unerstand basics of struts , advice welcome.
an additional piece of information: have been looking @ this blog in order figure out issue, have still not come solution.
if using jsp, understanding doing based on format of question header, format so(depending on how date changes way date built). this
<%@page import="java.text.simpledateformat, java.util.calendar, java.text.dateformat"%> <%@page contenttype="text/html" pageencoding="utf-8"%> <!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>date tester</title> </head> <body> <% dateformat dateformat = new simpledateformat("mm/dd/yyyy"); calendar cal = calendar.getinstance(); %> <form> <label for="date">your text field: </label><br/> <textarea type="" name="date" value="" >today's date: <%= dateformat.format(cal.gettime()) + "\n" %></textarea> <!-- rest of form here --> </form> </body> </html>
i hope helps! if not leave comment , seek again.
java html jsp struts2
Comments
Post a Comment