Formatting Dates in jsp
I want to format my dates inside a jsp page, which are all in yyyy-mm-dd format currently, to look like mm/dd/yyyy. Is there a way to do it? the fmt tag only seems to do extremely simple formatting (aka full, medium, etc, not real formatting).
Yawmark must be pining away for code likeUDateFormat* df = udat_open(UCAL_DEFAULT, UCAL_DEFAULT, NULL, "GMT", &status);
for (i = 0; i < 3; ++i) {
myStrlen = udat_format(df, myDateArr, NULL, myStrlen, NULL, &status);
if(status==U_BUFFER_OVERFLOW_ERROR){
status=U_ZERO_ERROR;
myString=(UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
udat_format(df, myDateArr[i], myString, myStrlen+1, NULL, &status);
printf("%s\n", austrdup(myString) );
/* austrdup( a function used to convert UChar* to char*) */
free(myString);
Similar Messages
-
how can i format a date java.util.Date or java.sql.Date
MM/DD/YYYY
DD/MM/YYYY
etc...
thinks like that any link o read?...Use JSTL tag as below ...
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<jsp:useBean id="now" class="java.util.Date" />
<fmt:setLocale value="en_GB"/>
[Try out yourself with other locales]
<fmt:formatDate value="${now}" type="both" pattern="EEEE, dd MM yyyy, HH:mm" />
Cheers
-Rohit -
How to download data in xml format from a jsp in IE
In my program, I am trying to download xml data from jsp. The problem I am facing is that the downloaded page opens in the browser itself. I want it to open in a new page. The same code works fine with csv and pdf format.
Hello
I am using a link that calls a javascript function. To show the file download box, I have used setContentType and setHeader functions in the jsp. Thanks. -
Formatting data in table - jsp & jdbc
Hey there friends!
I was having a little problem formatting data and I was looking for help!
I want to format the data from jdbc as follows on a jsp page
THIS IS REPORT TO GENERATE
Name | Worked | Refused | Training | CarryOver
Jim | 10 | 5 | 2 | 5
Bob | 20 | 5 | 10 |
The resultset that I retrieve from my database is like this
RESULTSET
ID | Name | Type | Hours | CarryOver
1 | Jim | Worked | 10 | 5
1 | Jim | Refused | 5 | 5
1 | Jim | Training | 10 | 5
2 | Bob | Worked | 20 | 10
2 | Bob | Training | 5 | 10
Can anyone suggest what can be a done here?As you have learnt something it is only fair for me for reciprocate.
The code example I gave you was psuedocode - not real java. You need to add in a couple more things to make it work correctly.
First we want to create an entry in the hash, iff there is no record already there, otherwise, we want to get the value and add our new value to it (let's say the map is called map):
String key = record.name + "/" + record.type; // Using combination string as the key - simplest solution
Long hours = map.get(key);
if (hours == null) {
hours = new Long(record.hours);
} else {
hours = new Long(hours.getValue() + record.hours);
map.put(key, hours);It would be better to use your own class to hold the long value - as this would save all the construction calls. -
How to print formated data/report on client's printer (Web Application)
Hi All
I want to print some formatted data/report ( it might be 1000 pages) on user's printer.
Application is web based
Technology used are Java - jsp - servlets
i want functionality like...
when user click on print button/link, data is fetched from server and all pages (it is formated data so i want alignment on page while printing) should be printed one after another.
Also printer selection dialog should displayed one time when user click on print button/link.
Questions:
1. How i will transfer all data to client (web browser) from the server ??
2. And how i can print that data on user's printer ??
There is requirement (or limitation) that I can not use applet for this purpose.
And also it is not fix that we must use java tech., we can use any othere tech. but condition is that it must support multiple platform (in short platform indipendant)
There is solution like ...
I can use window.print() function of DOM/JavaScript,
but it prints only one page which is displayed on browser.
I don't want to display any page. and want to print all pages.
if any one done or have idea then let me know.
Thanks in Adv.
Shailesh Koradiyathanks linxpda for reply,
we can use ActiveX component for windows platform for printing purpose, same way we can use platform specific component for printing... (for linux, unix, sun solaris etc...)
if it is possible then let me inform.
Thanks,
Shailesh Koradiya -
How to print formatted data / report on user's printer in Web Application
Hi All
I want to print some formatted data/report ( it might be 1000 pages) on user's printer.
application is web based and tech. used are Java - jsp - servlets
now prob. is ...
how i will transfer all data to client (web browser) from the server and how i can print that data on user's printer ...??
there is requirement that I can not use applet for this purpose.
if any one done or have idea then let me know.
thanks
Shailesh KoradiyaHi
Its simple, first of all break ur data in terms of pages. Write the logic in one JSP.
suppose i have jsp PrintReport.jsp , for page 1 url will PrintReport.jsp?page=0 ... so on
get the page parameter in JSP
String page="";
if(request.getParameter("page")!=null)
page=request.getParameter("page");
get the rowcount from the Result and assume records per page is 100
if u have 1000 rows then 10 pages u have to serve
StartRowNumber=page*recordsPerPage
EndRowNumber=StartRowNumber+recordsPerPage
Execute a SQL query , select * from table where rownum between
StartRowNumber and EndRowNumber
Provide google like pageNumbers in ur HTML page
ie 1 2 3 4 5 6 ..10
Regarding printing , Create HTML button called 'print' and add Javascript ' window.print()' on clicking it.
Hope it would solve ur problem
Cheers
Rajendra Bandi -
Need help in writing data from JSP to excel
Hi ,
I need help in writing the data from JSP to excel.I somehow able to retrieve the data into excel but unable to get the required format.
For eg: The amount should be displayed in 0.00 format .when i am exporting it to excel it is displaying as 0 :( .
I am using the following code in JSP.
"out.print(amt + '\t');"
Would like to know if there is any otherway where in i can get my requirement.
Thanks
TomHi,
Try using format part of the JSTL tag libs.
Syntax :
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<fmt:formatNumber value="40" pattern="$#,##0.00"/>
I need help in writing the data from JSP to excel.I
somehow able to retrieve the data into excelHow do u convert the jsp to excel?
One way to convert the jsp page to excel, is to render it as an excel appl instead of html. Set the content type of the response to application/ms-excel.
response.setContentType("application/ms-excel")Hope this Helps.... -
I have some dates fields on JSP page I want to store data in mysql databse. Can someone tell me how I can format dates as I do for other data types in servlet before I send data to add in databse: such as
For int type data:
String paymentID = request.getParameter("PaymentID")
I format it like this for class Payment.
Payment newPayment(int.parseInt(paymentID)
how do i work with date fields this is what I Am trying to do:
Code patches....
import java.text.DateFormat;\import java.text.ParseException;
public date date1;
try
date1= format.parse(paymentStartDate);
catch(ParseException pe)
System.out.println("Problem found");
....I do not get any error but it leaves date fields empty because date1 formatting never goes to try... Always say "Problem found on console"
Any help?I just realized I should post the whole file... here is code of the servlet that recieved dates from JSP and process it.
package admin;
import java.lang.Object.*;
import java.text.DateFormat;
import java.util.Date;
import java.io.IOException;
import java.text.ParseException;
import data.*;
import business.*;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class AddPaymentServlet extends HttpServlet{
public Date date1;
public Date date2;
public DateFormat format;
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
// Stores user entered Payment information in variables to create new Payment vector
String paymentID = request.getParameter("paymentID");
String clientName = request.getParameter("clientName");
String paymentType = request.getParameter("paymentType");
String paymentAmount = request.getParameter("paymentAmount");
String paymentStartDate = request.getParameter("paymentStartDate");
String paymentExpiryDate = request.getParameter("paymentExpiryDate");
String paymentDescription = request.getParameter("paymentDescription");
String paymentState1 = request.getParameter("paymentState"); // use String type of PaymentType
//-----------------------------------Format dates----------------------------------------------------------
DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.SHORT);
// System.out.println("Date1--->"+date1);
try
{ date1 = format.parse(paymentStartDate);
// System.out.println("Date1--->"+date1);
catch(ParseException ps)
System.out.println("can't format dates");
try
date2 = format.parse(paymentExpiryDate);
catch(ParseException pe)
System.out.println("can't format dates");
// get old Payment object from session
//--------------------------------Send new PAyment Information to Vector Payment in Payment.jave-----------------------------
Payment newPayment = new Payment(clientName,paymentType,Double.parseDouble(paymentAmount),date1,date2,paymentDescription,paymentState1);
//------------------------------ Call PaymentDB function Add() to store new payment infomration in the databse
PaymentDB.addRecord(newPayment);
// over-write Payment object in session
request.getSession().setAttribute("payment",newPayment);
request.getSession().setAttribute("payments",PaymentDB.readRecords());
//---------------------------------- Send results back to payment.jsp for updated information----------------------
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/Admin/payments.jsp");
dispatcher.forward(request, response);
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
doGet(request, response);
} -
Hi all,
JDEV IDE: Oracle IDE 9.0.3.9.93
I made a simple business component.
I tried to set the format of a date attribute in the Entity object and also in the View object.
I double clicked the attribute in structure window, changed Format Type in Control Hints tab to
"Simple Date" and Format to "dd-MM-yyyy" but running the tester or a JSP Page(BC4J) based on that component nothing changes. The format remains "yyyy-MM-dd".
What is the best approach to format Dates, Currencies and others in BC4J /JSP projects?
Thanks in advance
Email: [email protected]
Jan HultermansTry the following:
1. remove the formatting hint from the view object
2. setup the formatting on the entity object.
We recently fixed a bug in the view object formatting support. You workaround will be fine, but it is not the recommended approach since you will have to repeat the SQL changes for each view object that requires formatting. It will also break when a different locale comes in via the browser's http request parameters. -
Open a new window with data in jsp
Hi,
I am an absolute beginner.
I get data from DB in a pipe seperated string
retval = abc|123|xyz|999
I need to open a new window and populate the data in it.
1. How do i open a new window
2. How do i pass data to the new window
3. How can i display the formatted data in the new windowresponse.sendRedirect("newwindowurl.jsp?arg=" + retval);
This will direct users to a new window and pass the retval arg to it. On the other window, use request.getAttribute("retval"); to get the value passed in.
colr__ -
How to Hightlight the Data in Jsp Page
How to Hightlight the Data in Jsp Page,
I am doing doing search page,based on values given search page those are sent to servlet,in servlet based on some conditions if particuler id i am getting then i am redirecting to Respective jsp page with highlight the data from database..
Thanks in advance..."Highlighting data in JSP sounds strange".
Without looking at your search specific algorithms I feel you are finally going to display a page (HTML content) to user which contains highlighted text. Highlighting is not directly related to server side language you use (JSP, ASP, PHP etc.). This is purely HTML and CSS. However, server side script (such as JSP) should generate HTML content for getting highlight effect.
Following HTML shows highlighted text using background-color property on span element.
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
</head>
<body>
<p style="font-size:1.1em">This is a long paragraph which contains <span style="background-color: yellow;">highlighted text</span> and non highlighted text.</p>
</body>
</html>Thanks,
Mrityunjoy
Edited by: mrityunjoy on 14 Jun, 2010 3:30 AM -
Error When Refresh Formatted Data inside Excel Analyzer
I have build a Excel template and load up this to the BI Publisher Server. When I call this template after the log in works fine. When I refresh the data normal it works also fine, but when I try to refresh formatted Data I get the error "Error: This report does not support HTML as an output format." I will not use html output inside Excel, I will use the original Excel template with refreshed data.
Hi Tim,
The Refresh Formatted Data works on MS Excel 2003.
May need to check if its really supported on MS Office 2002.
Btw another question, is it possible to create an excel template without using Excel Analyzer?
Also when I used the generated excel file of Excel Analyzer as template, when the report is generated the data sheet sometimes is not filled with correct data or sometimes there is no data at all, even if the parameters used is the same as the one used in generating the original excel file using Excel Analyzer. This happens most of the time for reports with Concatenated Queries or SQL Queries using "CURSOR" to group a set of data. Note that on initial generation of excel file using Excel Analyzer, correct set of data is displayed. It is only when it is used as template and viewed/exported in Excel format that data is not properly loaded.
Please advise.
Thanks!
Uniz -
Error in outputting xml formatted data
Hello,
I'm trying to output xml formatted data using apex.
At about 70% into the formatted output I get this in the browser:
<descript>punct= & > < /,() &</descript>
</row>
- <row The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
Only one top level element is allowed in an XML document. Error processing resource 'http://apex.oracle.com/pls/otn/f?p=158...
<script language="JavaScript1.1" type="text/javascript">
-^
m">>
<DIVI have a 600 row table (dml below) with identical string in each row of the descript column. (I put in some special characters just to push it through the escape function for html. It is displaying the text correctly.)
The page has one report region (plsql below).
The page template is stripped down.
My local results are identical to the otn hosted workspace.
I did dump the table in xml format and displayed the dump file in browser without a problem, so I'm missing something in the code.
Thank you.
Albert
On OTN webspace, go to http://apex.oracle.com/pls/otn/f?p=15866:1:1291425545573680200:::::
plsql
declare
xdescript varchar2(4000);
begin
-- xml preface is in the page template
-- htp.p('<?xml version="1.0"?>');
htp.p('<rowset>');
begin
for item in
(select descript,cid from receipts order by cid)
loop
htp.p ('<row>');
xdescript := htf.escape_sc(item.descript);
htp.p('<cid>' || item.cid || '</cid>');
htp.p('<descript>'|| xdescript || '</descript>');
htp.p('</row>');
end loop;
end;
htp.p ('</rowset>');
end;
dml
CREATE TABLE "RECEIPTS"
( "CID" NUMBER,
"AMOUNT" NUMBER NOT NULL ENABLE,
"CLEARED" DATE,
"DESCRIPT" VARCHAR2(80),
"DATEENTERED" DATE DEFAULT SYSTIMESTAMP,
"CHECKNBR" NUMBER,
"CLEARSEQ" NUMBER DEFAULT 0,
CONSTRAINT "RECEIPTS_PK" PRIMARY KEY ("CID") ENABLE
CREATE SEQUENCE "RECEIPTS_SEQ" MINVALUE 1 MAXVALUE 999999999999999999999999999
INCREMENT BY 1 START WITH 4319 CACHE 20 NOORDER NOCYCLE
CREATE OR REPLACE TRIGGER "BI_RECEIPTS"
BEFORE INSERT ON "RECEIPTS"
FOR EACH ROW
BEGIN
SELECT "RECEIPTS_SEQ".NEXTVAL INTO :NEW.CID FROM DUAL;
END;
ALTER TRIGGER "BI_RECEIPTS" ENABLE
/May be it helps you. I use SQL/XML and APEX Application Process to generate XML succesfully
Here is the result:
http://htmldb.oracle.com/pls/otn/f?p=9774:101:0:APPLICATION_PROCESS=RSSNEWEVENTS
and here is the Process Text source:
declare
a clob;
begin
owa_util.mime_header( ccontent_type => 'text/xml', bclose_header => TRUE, ccharset => 'utf-8');
htp.prn('<?xml version="1.0" encoding="UTF-8"?>');
select
XMLTYPE.getStringVal(
XMLElement("rss",
XMLAttributes('2.0' as version),
XMLElement("channel",
XMLConcat(
XMLElement("title",'iActiveLife - novinky'),
XMLElement("link",'http://www.iactivelife.cz/'),
XMLElement("description",'iActiveLife - Zajímavý ivot snadněji'),
XMLElement("language",'cs'),
XMLElement("pubdate",''),
XMLAgg(
XMLElement("item",
XMLConcat(
XMLElement("title",event_name),
XMLElement("link",'http://htmldb.oracle.com/pls/otn/f?p=' || v('APP_ID') || ':37:' || v('SESSION') || '::NO::P37_EVENT_ID:' || event_id),
XMLElement("description",'')
) into a
from (
select event_id,event_name,issue_date, last_update_order
from (
select events.event_id, events.event_name, events.issue_date, rank () over (order by events.issue_date desc) as last_update_order
from events
where exists ( select * from opportunities where events.event_id=opportunities.event_id and opportunities.user_id is not null)
order by events.issue_date desc)
where last_update_order<=10
htp.prn(a);
end; -
How to use format-date with the report parameter
Hi all,
How to use the format-date function with this tag,
<?param@begin:P_FROM_DATE?><?$P_FROM_DATE?>
this form date is coming from report parameter and is coming like this 2012/11/01 00:00:00.
So now i need this in DD-MON-YYYY fromat.I tried like this <?param@begin:P_FROM_DATE?><?$format-date:P_FROM_DATE;'DD-MON-YYYY'?>
but its giving error. Can any one pls tell how to convert it to customized date format.
thanks & Regards
Srikkanth.MIssue solved.
Ref this link
XML date Format -
How to use many format data into a template?
How to design a template but it can interface from many format data?
This is the one from 2010 but should still work.
http://www.bfcnetworks.com/blogs/alexpearce/pull-sharepoint-2010-document-properties-into-word-quick-parts/
You basically create a new document in the library (must have the columns you want into the word document), then you use the Quick
Parts to insert the data where needed. Then you save this document as your template. Then anytime someone creates a document in the library when you open the document it will read from the columns of the item.
I used a workflow and had the users actually update a SharePoint list, then that in turn creates a new document in the document library and populate the columns from the list form. Then You can send that document link to folks to download / print or whatever.
Is that what you are talking about?
Maybe you are looking for
-
Hello, Bit of a beginner using Final Cut Pro 7 Am currently trying to export a sequence using quicktime conversion. Sequence has various filters and effects over it and when I export it some of the clips are pixellated and appear to have not exporte
-
I'm close to putting all of the pieces together for an Azure Cloud Services solution that I want to build. My goal is to build a .NET Library (or perhaps a Windows Service or even a Console Application) that will run once a day to execute dynamic qu
-
I have my MEGA180 on order but I already have some important questions: 1) This unit provides dual vga outputs. If I install my own AGP 8x card, will the VGA2 output still work? I read in the manual that installing an AGP card will disable VGA1 (defa
-
Reader 10.1.3 Won't Open - XP - Found a work around. why?
Out of the blue Reader would not open. Nothing. I would double click and nothing would launch. While viewing Task Manager I would see an Adobe exe in the list of running programs but then it would just disappear and reader didn't load. I uninstalled
-
Language is stuck on Japanese.Cannot reset
I have read the manual, been to tutorials and cannot find the settings to reset to english on ipod mini. Can someone please help>?!