DateFormat in JSP
Hi all,
I am getting the following date format
Sun Jun 05 00:00:00 GMT+05:30 2005 as output of the below mentioned function as the value of avldt :
<% Date avldt=new Date(ts.parse(dt).getTime());%>
<% out.println(avldt);%>
But I want to get 05-06-2005 instead of the above and then convert it into
2005-06-05 (YYYY-MM-DD) in order to store it into Mysql table as date field.
Please advice, what should i do for it ?
regards,
savdeep.
java.sql.Date.toString() gives the date in yyyy-MM-dd format. Anyway, you should make use of SimpleDateFormat for whatever format you need to display.
Similar Messages
-
Shell commands from JSP after Forms migration
During application migration from forms 9i to JSP & BC4J, I have to code the following Forms code into my JSP application.This is for a button pressed trigger.
DECLARE
RENAME_STRING VARCHAR2(120):= 'RENAME C:\BRC\PDATA' ||:DRAWING_ACCOUNTS.ACCOUNT_ID|| '.TXT P' || :DRAWING_ACCOUNTS.ACCOUNT_ID || TO_CHAR(SYSDATE,'DDMMYY')|| '.txt';
BEGIN
HOST( RENAME_STRING, no_screen );
web.show_document( 'http://hostname/selectfile.html', '_new');
IF NOT Form_Success THEN
Message('Error -- File not Renamed.');
END IF;
END;
How can I do this simple sending of OS commands in JSP, any ideas?Hi,
Not only rename commands but I have to pass several other os commands like 'sqlldr' for data upload as well. Therefore, I need a reusable piece of code for that. I have acheived some way for that using the following code.
put the following file in that package.
package BankrecBC4J;
import java.util.*;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.zip.*;
class StreamGobbler extends Thread
InputStream is;
String type;
StreamGobbler(InputStream is, String type)
this.is = is;
this.type = type;
public void run()
try
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line=null;
while ( (line = br.readLine()) != null)
System.out.println(type + ">" + line);
} catch (IOException ioe)
ioe.printStackTrace();
public class GoodWindowsExec
private static final boolean NATIVE_COMMANDS = true;
//Allow browsing and file manipulation only in certain directories
private static final boolean RESTRICT_BROWSING = false;
//If true, the user is allowed to browse only in RESTRICT_PATH,
//if false, the user is allowed to browse all directories besides RESTRICT_PATH
private static final boolean RESTRICT_WHITELIST = false;
//Paths, sperated by semicolon
//private static final String RESTRICT_PATH = "C:\\CODE;E:\\"; //Win32: Case important!!
private static final String RESTRICT_PATH = "/etc;/var";
* Command of the shell interpreter and the parameter to run a programm
private static final String[] COMMAND_INTERPRETER = {"cmd", "/C"}; // Dos,Windows
//private static final String[] COMMAND_INTERPRETER = {"/bin/sh","-c"}; // Unix
* Max time in ms a process is allowed to run, before it will be terminated
private static final long MAX_PROCESS_RUNNING_TIME = 30 * 1000; //30 seconds
//Normally you should not change anything after this line
//Change this to locate the tempfile directory for upload (not longer needed)
private static String tempdir = ".";
private static String VERSION_NR = "1.1a";
private static DateFormat dateFormat = DateFormat.getDateTimeInstance();
public GoodWindowsExec(String g)
System.out.println(" hello " + g);
/*if (g.length < 1)
System.out.println("USAGE: java GoodWindowsExec <cmd>");
System.exit(1);
try
String osName = System.getProperty("os.name" );
String[] cmd = new String[3];
System.out.println("here ");
if( osName.equals( "Windows NT" ) )
cmd[0] = "cmd.exe" ;
cmd[1] = "/C" ;
cmd[2] = g;
else if( osName.equals( "Windows 2000" ) )
System.out.println("Windows 2000");
cmd[0] = "command.com" ;
cmd[1] = "/C" ;
cmd[2] = g;
else if( osName.equals( "Windows XP" ) )
System.out.println("Windows XP");
cmd[0] = "command.com" ;
cmd[1] = "/C" ;
cmd[2] = g;
else if( osName.equals( "Windows 95" ) )
cmd[0] = "command.com" ;
cmd[1] = "/C" ;
cmd[2] = g;
Runtime rt = Runtime.getRuntime();
System.out.println("Execing " + cmd[0] + " " + cmd[1]
+ " " + cmd[2]);
Process proc = rt.exec(cmd);
* Starts a native process on the server
* @param command the command to start the process
* @param dir the dir in which the process starts
// any error message?
StreamGobbler errorGobbler = new
StreamGobbler(proc.getErrorStream(), "ERROR");
// any output?
StreamGobbler outputGobbler = new
StreamGobbler(proc.getInputStream(), "OUTPUT");
// kick them off
errorGobbler.start();
outputGobbler.start();
// any error???
int exitVal = proc.waitFor();
System.out.println("ExitValue: " + exitVal);
} catch (Throwable t)
t.printStackTrace();
* Converts some important chars (int) to the corresponding html string
static String conv2Html(int i) {
if (i == '&') return "&";
else if (i == '<') return "<";
else if (i == '>') return ">";
else if (i == '"') return """;
else return "" + (char) i;
static String startProcess(String command, String dir) throws IOException {
StringBuffer ret = new StringBuffer();
String[] comm = new String[3];
comm[0] = COMMAND_INTERPRETER[0];
comm[1] = COMMAND_INTERPRETER[1];
comm[2] = command;
long start = System.currentTimeMillis();
try {
//Start process
Process ls_proc = Runtime.getRuntime().exec(comm, null, new File(dir));
//Get input and error streams
BufferedInputStream ls_in = new BufferedInputStream(ls_proc.getInputStream());
BufferedInputStream ls_err = new BufferedInputStream(ls_proc.getErrorStream());
boolean end = false;
while (!end) {
int c = 0;
while ((ls_err.available() > 0) && (++c <= 1000)) {
ret.append(conv2Html(ls_err.read()));
c = 0;
while ((ls_in.available() > 0) && (++c <= 1000)) {
ret.append(conv2Html(ls_in.read()));
try {
ls_proc.exitValue();
//if the process has not finished, an exception is thrown
//else
while (ls_err.available() > 0)
ret.append(conv2Html(ls_err.read()));
while (ls_in.available() > 0)
ret.append(conv2Html(ls_in.read()));
end = true;
catch (IllegalThreadStateException ex) {
//Process is running
//The process is not allowed to run longer than given time.
if (System.currentTimeMillis() - start > MAX_PROCESS_RUNNING_TIME) {
ls_proc.destroy();
end = true;
ret.append("!!!! Process has timed out, destroyed !!!!!");
try {
Thread.sleep(50);
catch (InterruptedException ie) {}
catch (IOException e) {
ret.append("Error: " + e);
return ret.toString();
In the first line of the JSP file include the package
<%@page import="BankrecBC4J.*" %>
and call
it this way:from the jsp page
new GoodWindowsExec ("calc"); //
which should open up the calciulator, and should do for other os commands as well.
Thanks -
JSPs and Servlets do not work on Apache HTTP- Procesor Intel P4
Computer description: Intel Pentium 4 processor with 20GB HD
drive, 1GB RAM, Windows 2000Pro, Service pack II
Before installation:
We created a temporary directory on our Intel Pentium. 4
processor server (e.g. \TEMP).
Copied the contents of the Oracle* Server CD to the temporary
directory.
Renamed each copy of the SYMCJIT.DLL to SYMCJIT.OLD.
Set the java_compiler=none environment variable.
Installation:
We run the SETUP.EXE from the \TEMP\install\win32 directory and
install Oracle 8.1.7 EE Rel 3 Typical
Configuration tool Net8 Configuration Assistant succeeded
Configuration tool Oracle Database Configuration Assistant
succeeded
Configuration tool Starting Oracle HTTP service: 7 times error
message (java.exe has generated errors and will be closed by
Windows, You will need to restart the
program, An error log is being created)
HTTP server responses.
All Java programs do not respond (e.g. IsItWorking does not work)
After installation:
Open the jserv.conf file chack that ApJServManual is set to Off.
set ApJServLogLevel debug (will give more informative errors for
debugging)
set ApJServDefaultHost www.in.oracle.com (to your machine name
with the
domain name or IP address)
set ApjServDefaultPort 80000
Open the jserv.properties files and make the following changes:
bindaddress=www.in.oracle.com (Same name as ApJServDefaultHost
in jserv.conf)
port=80000 (same port as in the jserv.conf)
Enable all log options in jserv.properties:
log=true
log.file=/usr/local/apache/var/log/jserv.trace
log.timestamp=true
log.dateFormat=[yyyyMMdd HHmmss:SSS]
log.channel.init=true
log.channel.terminate=true
log.channel.serviceRequest=true
log.channel.authentication=true
log.channel.requestData=true
log.channel.responseHeaders=true
log.channel.signal=true
log.channel.exceptionTracing=true
log.channel.servletManager=true
Java servlets and JSP still do not redspond.
If we try to start HTTP server from Windows service, we always
get message: unable to locate dll: The dynamic link
library Perl.dll could not be found in the secified path (our
path: C:\oracle\ora81\bin;C:\oracle\ora81\Apache\Perl\5.00503
\bin\mswin32-x86;
C:\Program Files\Oracle\jre\1.1.7
\bin;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;) and
error message: Could not start
OracleOraHome81HTTPServer service on local computer. The service
did not respond to the start or control request in a
timely fashion.
Starting Oracle HTTP service from Start/Programs/Oracle: 7 times
error message (java.exe has generated errors and will be closed
by Windows, You will need to restart the
program, An error log is being created)
We tested also modifications of oraparam.ini
a. Copy only the install directory from the CD to the hard
disk ,say, e:\temp.
b. Open oraparam.ini and make the following modifications
(Assuming CD
drive is f:)
* Change the "SOURCE=" line to use the full path to the CD
instead of a
relative path. (i.e., SOURCE=f:\stage\products.jar)
* Change the "JRE_LOCATION" line to use the full path to the CD
instead of a
relative path. (i.e.,
JRE_LOCATION=f:\stage\Components\oracle\swd\jre\1.1.7\1
\DataFiles\Expanded)
* Change the "OUI_LOCATION" line to use the full path to the CD
instead of a
relative path. (i.e.,
OUI_LOCATION=f:\stage\Components\oracle\swd\oui\1.6.0.9.0\1
\DataFiles\Expanded
* Change the "JRE_MEMORY_OPTIONS" line to add "-nojit" as the
first argument.
(i.e., JRE_MEMORY_OPTIONS=-nojit -ms16m -mx32m)
^^^^^^
* Other entries should remain the same
c. Launch setup.exe from the temporary location on your hard
drive (i.e.
e:\temp\install\ win32\setup.exe). This will use the modified
oraparam.ini and pick up the information from the CD since the
absolute
locations are specified.
After that modification of oraparam.ini, the HTTPServer does not
respond at all.
So we undo changes on oraparam.ini and reinstall HTTP.
We copied SYMCJIT.DLL and jvm.dll from JDK 1.1.8_008 to
Apache\jdk\..
Since then at least the demo IsItWorking responses, but database
connection can not be established. But jsp demo still do not?
THX in advance
NejaI'm still having problems with Portal config (as part of 9iAS) on
a P4 but i have cleared the hurdle of the HTTP listener (i
think).
I downloaded and installed the JRE that is P4 compatible from
www.sun.com (it puts it under c:\program files)
then overwrote all the files in the jre directories in the cd
staging area with the files from Sun (i.e. all symcjit.dll
locations). I also had to put a file "javai.dll" in the same
directory as the file "java.exe". This got the install all
working.
The service will fail first time because the install creates
another set of incompatible jre files. You must again search for
symcjit and repeat the above procedure.
You must also overwrite the files in the c:\program
files\oracle\inventory\jre directories (sorry cant remember exact
path).
Hope this helps.
Mark Gornicki
PS if anyone knows why Portal config hangs at 67%
(before/during/after processing "bulkload.jar" section) please
let me know :-) -
How to retrieve records from a database and display it in a jsp page.Help!!
Hello everyone ! im very new to this forum.Please help me to solve my problem
First i ll explain what is my requirement or needed.
Actually in my web page i have text box to enter start date and end date
and one list box to select the month .If user select or enter the dates in text box
accordingly the data from ms access database has to display in a jsp page.
Im using jsp and beans.
I tried returning ResultSet from bean but i get nothing display in my web page
instead it goes to error page (ErrorPage.jsp) which i handle in the jsp.
I tried many things but nothing work out please help me to attain a perfect
solution. I tried with my bean individually to check whether the result set has
values but i got NullPointerException . But the values which i passed or
available in the database.
I dint get any reply for my last post please reply atleast to this.
i get the date in the jsp page is by this way
int Year=Integer.parseInt(request.getParameter("year"));
int Month=Integer.parseInt(request.getParameter("month"));
int Day=Integer.parseInt(request.getParameter("day"));
String startdate=Day+"/"+Month+"/"+Year;
int Year1=Integer.parseInt(request.getParameter("year1"));
int Month1=Integer.parseInt(request.getParameter("month1"));
int Day1=Integer.parseInt(request.getParameter("day1"));
String enddate=Day1+"/"+Month1+"/"+Year1;But this to check my bean whether it return any result!
public void databaseConnection(String MTName,String startDate,String endDate)
try
java.text.SimpleDateFormat dateFormat=new java.text.SimpleDateFormat("dd/MM/yyyy");
java.util.Date fromDate=dateFormat.parse(startDate);
java.util.Date tillDate=dateFormat.parse(endDate);
java.sql.Date sqlFromDate=new java.sql.Date(fromDate.getTime());
java.sql.Date sqlTillDate=new java.sql.Date(tillDate.getTime());
String query1="select MTName,Date,MTLineCount from Main where MTName='"+MTName+"' and Date between '"+sqlFromDate+"' and '"+sqlTillDate+"' " ;
System.out.println(query1);
Class.forName(driver);
DriverManager.getConnection(url);
preparedStatement=connection.prepareStatement(query1);
preparedStatement.setString(1,"MTName");
preparedStatement.setDate(2,sqlFromDate);
preparedStatement.setDate(3,sqlTillDate);
resultSet=preparedStatement.executeQuery();
while(resultSet.next())
System.out.println(resultSet.getString(1));
System.out.println(resultSet.getDate(2));
System.out.println(resultSet.getInt(3));
catch (Exception e)
e.printStackTrace();
I Passed value from my main method is like thisl
databaseConnection("prasu","1/12/2005","31/12/2005");Please provide solutions or provide some sample codes!
Help!
Thanks in advance for repliesThanks for ur reply Mr.Rajasekhar
I tried as u said,
i tried without converting to sql date ,but still i din't get any results
java.text.SimpleDateFormat dateFormat=new java.text.SimpleDateFormat("dd/MM/yyyy");
java.util.Date fromDate=dateFormat.parse(startDate);
java.util.Date tillDate=dateFormat.parse(endDate);
String query1="select MTName,Date,MTLineCount from linecountdetails where mtname='"+MTName+"' and Date >='"+fromDate+"' and Date <='"+tillDate+"' " ;
System.out.println(query1);
//From main method
databaseConnection("prasu","1/12/2005","31/12/2005");I got the output as
---------- java ----------
select MTName,Date,MTLineCount from linecountdetails where mtname='prasu' and Date >='Thu Dec 01 00:00:00 GMT+05:30 2005' and Date <='Sat Dec 31 00:00:00 GMT+05:30 2005'
java.lang.NullPointerException
null
null
java.lang.NullPointerException
Output completed (4 sec consumed) - Normal TerminationThanks
Prasanna.B -
How can I display the date on a jsp page??
Is there anyway to display the current date when someone views a jsp page??? Can I get it from the server or something like that?
Thx
Richis there any type of formatting that goes witth
that.....Most definitely -- check out the java.text.DateFormat object and its cohort java.text.SimpleDateFormat.
For example, if you wanted to display the current date in MM/DD/YYYY format, you could do the following:
<%-- This could go somewhere near the top of the JSP %>
<%
SimpleDateFormat f = new SimpleDateFormat("MM/dd/yyy");
%>
<% And later on, you could have... %>
<%= f.format(new Date()); %>Note that I've omitted the proper <%import%> directives.
-Navin -
HOW TO: Create a JSP Edit Record Form Using BC4J Data Tags
This is a JDeveloper Tech Note found on the OTN Documentation page. This note describes the use of the BC4J data tags to create row edit/submit JSP pages. Here is the link:
http://technet.oracle.com/docs/products/jdev/technotes/datatag_input/Edit_Form.htmlAre you using Java 1.4.* ?
Use JFormattedTextField.
import javax.swing.*;
import java.text.*;
import java.awt.*;
import java.util.*;
public class DateExample
public static void main( String [] args )
// Here's what you're interested in...
DateFormat dateFormat = new SimpleDateFormat( "MM/dd/yyyy" );
JFormattedTextField field = new JFormattedTextField( dateFormat );
field.setColumns( 11 );
field.setText( dateFormat.format(new Date()) );
JPanel panel = new JPanel();
panel.add( field );
panel.add( new JButton( "Hey" ) );
JFrame f = new JFrame();
f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
f.getContentPane().add( panel );
f.pack();
f.setVisible( true );
}It also works with other types of Format objects (ex. Currency, Decimal, etc.) -
JSP Calendar Wizard/PopUp Window
I am looking for a Calendar Wizard that I can include into my JSP,
with the ability to scroll between months, and have the user select a specific date that can be returned to the calling JSP.
I do not want to use an Applet, it must be pure JSP/Java code.
Can you please make some suggestions.
Thank you.
BharatThank you, I used your solution/code.
I required a pop/up calendar for a multi-language application, and the days and month names had to be langauge specific based on the locale.
Herewith is my solution:
1). Code from the calling JSP
<script>
function openPopupCalendar(urlToOpen)
var window_width = screen.availWidth*1/3;
var window_height = screen.availHeight/2.8;
var window_left = (screen.availWidth/2)-(window_width/2);
var window_top = (screen.availHeight/2)-(window_height/2);
var winParms = "resizable=yes" + ",height="+window_height+
",width="+window_width + ",left="+window_left+
",top="+window_top;
window.open(urlToOpen,'_blank',winParms);
</script>
<input type="text" id="calendarPopUp" name="valueFrom" size="25" onDblClick="openPopupCalendar('../Cal/Cal.jsp?formName=form1&where=valueFrom')">
2). The Calendar/Pop-up JSP
<%--
File: Cal.jsp
Description: pop up Calendar
--%>
<!-- Standard Jsp stuff -->
<% response.setHeader("Cache-control","no-cache"); %>
<%@ page
errorPage="/error.jsp"
isThreadSafe="true"
import="javax.naming.*,
java.util.Calendar,
java.util.Date,
java.util.GregorianCalendar,
java.util.Locale,
com.rubico.bcb.util.*,
java.text.SimpleDateFormat,
java.text.DateFormat"
%>
<%@ taglib uri="/RubicoTaglib1" prefix="r" %>
<r:locale/>
<r:resource resource="Calendar" />
<html>
<link rel="stylesheet" type="text/css" href="../StyleSheets/RGStyle.css">
<head>
<title><r:l>CALENDAR</r:l></title>
<script LANGUAGE="JAVASCRIPT">
function gotoPage(){
var year = document.selectdate.year.value;
var month = document.selectdate.month.options[document.selectdate.month.selectedIndex].value;
if ((month=="")||(month==null)) {
alert("Please enter a month and year.");
return false;
if ((year=="")||(year==null)) {
alert("Please enter a month and year.");
return false;
document.location = 'Cal.jsp?year='+year+'&month='+month+'&formName=<%= request.getParameter("formName")%>&where=<%= request.getParameter("where")%>';
</script>
</head>
<body>
<center>
<FORM NAME="selectdate">
<!--<h3>Please select a date.</h3>-->
<%
Calendar calendar = new GregorianCalendar();
Date trialTime = new Date();
calendar.setTime(trialTime);
Calendar calendar2 = new GregorianCalendar();
calendar2.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), 1);
int today = calendar.get(Calendar.DAY_OF_MONTH);
int currentYear = calendar.get(Calendar.YEAR);
String Month = "";
String ymd = "";
String formatDate = "";
%>
<%
int daynum= 1;
int column = 1;
int row = 1;
%>
<%
int year = 0;
int month = 0;
int monthPlus = 0;
Locale theLocale = (Locale)session.getAttribute("localeObj");
DateFormat sdf = DateFormat.getDateInstance(DateFormat.MEDIUM,theLocale);
java.util.Date pass_in_to_date = null;
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
String y = request.getParameter("year");
if (y==null) {
year = calendar2.get(Calendar.YEAR);
else
year = Integer.parseInt(y);
calendar2.set(year,calendar2.get(Calendar.MONTH),1);
String m = request.getParameter("month");
if (m==null) {
month = calendar2.get(Calendar.MONTH);
else
month = Integer.parseInt(m);
calendar2.set(calendar2.get(Calendar.YEAR),month,1);
int firstDay = calendar2.get(Calendar.DAY_OF_WEEK);
%>
<%
monthPlus = month;
monthPlus = ++monthPlus;
switch (month) {
case Calendar.JANUARY: Month = "JANUARY";break;
case Calendar.FEBRUARY: Month = "FEBRUARY";break;
case Calendar.MARCH: Month = "MARCH";break;
case Calendar.APRIL: Month = "APRIL";break;
case Calendar.MAY: Month = "MAY";break;
case Calendar.JUNE: Month = "JUNE";break;
case Calendar.JULY: Month = "JULY";break;
case Calendar.AUGUST: Month = "AUGUST";break;
case Calendar.SEPTEMBER: Month = "SEPTEMBER";break;
case Calendar.OCTOBER: Month = "OCTOBER";break;
case Calendar.NOVEMBER: Month = "NOVEMBER";break;
case Calendar.DECEMBER: Month = "DECEMBER";break;
%>
<TABLE border="1" cellpadding="0" cellspacing="0" WIDTH="200" ALIGN="CENTER" >
<TR>
<TD ALIGN="CENTER" COLSPAN="4" >
<SELECT NAME="month" SIZE="1" ONCHANGE="gotoPage();return false;">
<OPTION VALUE="0" <% if (month==0){%>SELECTED<% } %>><r:l>JAN</r:l></OPTION>
<OPTION VALUE="1" <% if (month==1){%>SELECTED<% } %>><r:l>FEB</r:l></OPTION>
<OPTION VALUE="2" <% if (month==2){%>SELECTED<% } %>><r:l>MAR</r:l></OPTION>
<OPTION VALUE="3" <% if (month==3){%>SELECTED<% } %>><r:l>APR</r:l></OPTION>
<OPTION VALUE="4" <% if (month==4){%>SELECTED<% } %>><r:l>MAY</r:l></OPTION>
<OPTION VALUE="5" <% if (month==5){%>SELECTED<% } %>><r:l>JUN</r:l></OPTION>
<OPTION VALUE="6" <% if (month==6){%>SELECTED<% } %>><r:l>JUL</r:l></OPTION>
<OPTION VALUE="7" <% if (month==7){%>SELECTED<% } %>><r:l>AUG</r:l></OPTION>
<OPTION VALUE="8" <% if (month==8){%>SELECTED<% } %>><r:l>SEP</r:l></OPTION>
<OPTION VALUE="9" <% if (month==9){%>SELECTED<% } %>><r:l>OCT</r:l></OPTION>
<OPTION VALUE="10" <% if (month==10){%>SELECTED<% } %>><r:l>NOV</r:l></OPTION>
<OPTION VALUE="11" <% if (month==11){%>SELECTED<% } %>><r:l>DEC</r:l></OPTION></SELECT>
<input type="text" name="year" size="7" value="<%=year %>" ONCHANGE="gotoPage();return false;">
</TR>
<TR valign="top" >
<TD valign="top" align="left" class="header" WIDTH="20%"><IMG SRC="../images/cal.gif" BORDER="0" WIDTH="20" HEIGHT="20"> </TD>
<TD valign="middle" colspan="2" ALIGN="CENTER" class="header" WIDTH="60%"><r:llabel><%= Month %></r:llabel> <%= year %></TD>
<TD valign="top" align="right" class="header" WIDTH="20%"><IMG SRC="../images/cal.gif" BORDER="0" WIDTH="20" HEIGHT="20"> </TD>
</TR>
<TR>
<TD CLASS="FORMTABLE" COLSPAN="4">
<TABLE border="0" cellpadding="0" cellspacing="0" WIDTH="100%" >
<!--<TR>
<TD CLASS="FORMTABLE" ALIGN="RIGHT"><B>Year</B></TD>
<TR>
<TD COLSPAN="7" ALIGN=center CLASS="FORMTABLE"><B>
<%= Month %> <%= year %></B></TD>
</TR>-->
<TR>
<TD ALIGN=center CLASS="header2"><r:l>SUN</r:l></TD>
<TD ALIGN=center CLASS="header2"><r:l>MON</r:l></TD>
<TD ALIGN=center CLASS="header2"><r:l>TUE</r:l></TD>
<TD ALIGN=center CLASS="header2"><r:l>WED</r:l></TD>
<TD ALIGN=center CLASS="header2"><r:l>THU</r:l></TD>
<TD ALIGN=center CLASS="header2"><r:l>FRI</r:l></TD>
<TD ALIGN=center CLASS="header2"><r:l>SAT</r:l></TD>
</TR>
<TR>
<%
int maxdays = calendar2.getActualMaximum(Calendar.DAY_OF_MONTH);
String max = String.valueOf(maxdays);
while (daynum<=maxdays) {
if (row==1) {
for (int j=1; j<firstDay; j++) {
%><TD ALIGN=center CLASS="FORMTABLE"> </TD>
<%
column++;
while ((column<8)&&(daynum<=maxdays)) {
ymd = (year + "-" + monthPlus + "-" + daynum);
pass_in_to_date = sdf2.parse(ymd);
formatDate = sdf.format(pass_in_to_date);
%>
<TD ALIGN="CENTER" CLASS="FORMTABLE"><B><a href=" ONCLICK="sendDate('<%= formatDate %">'); return false;" <% if ((calendar.get(Calendar.MONTH))==(calendar2.get(Calendar.MONTH))&&(calendar.get(Calendar.YEAR))==(calendar2.get(Calendar.YEAR))&&(calendar.get(Calendar.DAY_OF_MONTH))==daynum) { %>CLASS="RED"<% } %>><%= daynum %></A></B></td>
<input TYPE="hidden" ID="hidDate<%= daynum %>" NAME="hidDate<%= daynum %>" value="<%=formatDate %>">
<%
column++;
daynum++;
if (column!=8) {
for (int j=column; j<8; j++) {
%><TD ALIGN="CENTER" CLASS="FORMTABLE"> </TD><%
%></TR><% if (daynum<maxdays) { %><TR><% } %><%
column=1;
row++;
%>
</TABLE></TD>
</TR>
<TR>
<TD COLSPAN="2" ALIGN="LEFT" CLASS="FORMTABLE" ><IMG SRC="../images/cal.gif" BORDER="0" WIDTH="20" HEIGHT="20"> </TD>
<TD COLSPAN="2" ALIGN="RIGHT" CLASS="FORMTABLE" ><IMG SRC="../images/cal.gif" BORDER="0" WIDTH="20" HEIGHT="20"> </TD>
</TR>
</TABLE>
<center>
<script LANGUAGE="JAVASCRIPT">
function sendDate(date){
opener.document.<%=request.getParameter("formName")%>['<%= request.getParameter("where")%>'].value = ""+date+"" ;
window.close();
</script>
<BR>
</FORM>
</body>
</HTML>
</a> -
How to open a 'Save As' Dialog box in JSP?
Hi all, i need to export a CSV file. A button is provided to the user to choose the directory to save the file. My problem is how to open a 'Save As' dialog box in JSP?
Thanks in advanceHi,
Below is my full code to download fiel but still the Save Dialog box still not show..
<%@ taglib prefix="cs" uri="futuretense_cs/ftcs1_0.tld"
%><%@ taglib prefix="asset" uri="futuretense_cs/asset.tld"
%><%@ taglib prefix="assetset" uri="futuretense_cs/assetset.tld"
%><%@ taglib prefix="commercecontext" uri="futuretense_cs/commercecontext.tld"
%><%@ taglib prefix="ics" uri="futuretense_cs/ics.tld"
%><%@ taglib prefix="listobject" uri="futuretense_cs/listobject.tld"
%><%@ taglib prefix="render" uri="futuretense_cs/render.tld"
%><%@ taglib prefix="siteplan" uri="futuretense_cs/siteplan.tld"
%><%@ taglib prefix="searchstate" uri="futuretense_cs/searchstate.tld"
%><%@ taglib prefix="locale" uri="futuretense_cs/locale1.tld"
%><%@ taglib prefix="dateformat" uri="futuretense_cs/dateformat.tld"
%><%@ taglib prefix="blobservice" uri="futuretense_cs/blobservice.tld"
%><%@ taglib prefix="satellite" uri="futuretense_cs/satellite.tld"
%><%@ taglib prefix="date" uri="futuretense_cs/date.tld"
%><%@ page import="COM.FutureTense.Interfaces.*,
COM.FutureTense.Util.ftMessage,
COM.FutureTense.Util.ftErrors"
%><%@ page import="COM.FutureTense.Interfaces.*,
COM.FutureTense.Util.ftMessage,
COM.FutureTense.Util.ftErrors"
%>
<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ page import="java.io.File" %>
<%@ page import="java.io.OutputStream" %>
<%@ page import="java.io.FileInputStream" %>
<cs:ftcs><%-- france/test_template
INPUT
OUTPUT
--%>
<%-- Record dependencies for the Template --%>
<ics:if condition='<%=ics.GetVar("tid")!=null%>'><ics:then><render:logdep cid='<%=ics.GetVar("tid")%>' c="Template"/></ics:then></ics:if>
<%
String fileToFind = request.getParameter("file");
if(fileToFind == null) return;
File fname = new File(fileToFind);
System.out.println("Save As: "+fname.getName() );
if(!fname.exists()) return;
FileInputStream istr = null;
response.setContentType("application/octet-stream;charset=ISO-8859-1");
response.setHeader("Content-Disposition", "attachment; filename=\"" + fname.getName() + "\";");
try {
istr = new FileInputStream(fname);
int curByte=-1;
while( (curByte=istr.read()) !=-1){
out.write(curByte);
out.flush();
} catch(Exception ex){
ex.printStackTrace(System.out);
} finally{
try {
if(istr!=null) istr.close();
} catch(Exception ex){
System.out.println("Major Error Releasing Streams: "+ex.toString());
try {
response.flushBuffer();
} catch(Exception ex){
System.out.println("Error flushing the Response: "+ex.toString());
%>
</cs:ftcs>
Can anybody help me with this???
Thank you in advance. -
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);
} -
Problem in parsing date having Chinese character when dateformat is 'MMM'
I m calling jsp page using following code:
var ratewin = window.showModalDialog("Details.jsp?startDate="+startDate,window, dlgSettings );
In my javascript when checked by adding alerts I m getting correct values before passing to jsp,
alert("startDate:"+startDate);
In jsp page my code is like below:
String startDate = request.getParameter("startDate");
but here I m getting garbage values in month when the dateformat is 'MMM', because of which date parsing is failing.
This happens only Chinese character.
following 2 encoding are already in my jsp page,can anyone help to find solution?
<%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"/>
I have even tried to read it as UTF-8 but still that's failing.This is my actual code
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class TestingDate {
* @param args
public static void main(String[] args) {
// TODO Auto-generated method stub
String dateFormat="EEEE, MMM d h:mm a";
Date test=new Date(2007,0,19, 19, 31);
System.out.println(" original date is "+test);
String stringResult=DateToString(test,dateFormat);
System.out.println("Date to string is "+stringResult);
Date dateResult=stringToDate(stringResult,dateFormat);
System.out.println(" String to date is "+dateResult);
String stringResult2=DateToString(dateResult,dateFormat);
System.out.println(" Date to string is "+stringResult2);
public static String DateToString(Date test, String dateFormat) {
String result = null;
try {
DateFormat myDateFormat = new SimpleDateFormat(dateFormat);
result = myDateFormat.format(test);
//System.out.println(" reslut date is "+result);
} catch (Exception e) {
System.out.println(" Exception is "+e);
return result;
public static Date stringToDate(String strDate,String dateFormat1){
Date result1=null;
try {
DateFormat myDateFormat = new SimpleDateFormat(dateFormat1);
result1=myDateFormat.parse(strDate);
catch(Exception e){
System.out.println(" exception is "+e);
return result1;
}I am facing problem in getting the actual date. Please suggest the solution. -
How to display the JSP output in the same page....
im new to JSP..... can anyone tell me how to display the output of a particular JSP page in the same page itself...... if anyone could send a small sample code it will be very useful for me....
thanks in advance
regds
Krish......Hi Robert -
When you say you are writing a template-based Renderer, do you mean that you are creating a custom look and feel and replacing the header Renderer? If so, I'd recommend instead simply creating your own template (not template-based Renderer), and reference your template directly from your uiXML pages where you want to insert the timestamp.
You'll probably want to write a method data provider which calls System.currentTime(), convert the result to a date, and then use Java's date formatting capabilities (see java.text.format.DateFormat) to produce a user presentable String that you can return from your data provider.
For more info (and samples) on templates and data binding, see the "Templates and Data Binding" section of the "Includes and Templating in ADF UIX" help topic:
http://tinyurl.com/5b7bf
Andy -
Errors in a program jsp with javabeans
With the following program time.jsp from the book bigjava by
horstmann, I get from tomcat 5.0 the following errors. Who helps me?
My O.S. is win pro.
Thanks
Eugenia Mariani
this is the program:
time.jsp
inside the folder
C:\Programmi\Apache Software Foundation\Tomcat 5.0\webapps\bigjava
<jsp:useBean id="formatter" class="TimeFormatterBean"/>
<jsp:setProperty name="formatter" property="date" value="<%= new
java.util.Date() %>"/>
<html>
<head>
<title>Time JSP</title>
</head>
<body>
<h1>Time JSP</h1>
<p>The current time is:
<jsp:getProperty name="formatter" property="time"/>
</p>
</body>
</html>
this is the program TimeFormatterBean.java with
TimeFormatterBean.class
inside the folder:
C:\Programmi\Apache Software Foundation\Tomcat
5.0\webapps\bigjava\WEB-INF\classes
import java.text.DateFormat;
import java.util.Date;
This bean formats the time of day from a given date.
public class TimeFormatterBean
Initializes the formatter.
public TimeFormatterBean()
timeFormatter = DateFormat.getTimeInstance();
Write-only date property.
@param aDate the date to be formatted.
public void setDate(Date aDate)
theDate = aDate;
Read-only time property.
@return the formatted time
public String getTime()
String timeString = timeFormatter.format(theDate);
return timeString;
private DateFormat timeFormatter;
private Date theDate;
these are the errors fro TOMCAT 5.0
HTTP Status 500 -
type Exception report
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
description The server encountered an internal error () that prevented
it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 1 in the jsp file: /time.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\Programmi\Apache Software Foundation\Tomcat
5.0\work\Catalina\localhost\bigjava\org\apache\jsp\time_jsp.java:42:
cannot resolve symbol
symbol : class TimeFormatterBean
location: class org.apache.jsp.time_jsp
TimeFormatterBean formatter = null;
^
An error occurred at line: 1 in the jsp file: /time.jsp
Generated servlet error:
C:\Programmi\Apache Software Foundation\Tomcat
5.0\work\Catalina\localhost\bigjava\org\apache\jsp\time_jsp.java:44:
cannot resolve symbol
symbol : class TimeFormatterBean
location: class org.apache.jsp.time_jsp
formatter = (TimeFormatterBean)
jspxpage_context.getAttribute("formatter", PageContext.PAGE_SCOPE);
^
An error occurred at line: 1 in the jsp file: /time.jsp
Generated servlet error:
C:\Programmi\Apache Software Foundation\Tomcat
5.0\work\Catalina\localhost\bigjava\org\apache\jsp\time_jsp.java:46:
cannot resolve symbol
symbol : class TimeFormatterBean
location: class org.apache.jsp.time_jsp
formatter = new TimeFormatterBean();
^
An error occurred at line: 10 in the jsp file: /time.jsp
Generated servlet error:
C:\Programmi\Apache Software Foundation\Tomcat
5.0\work\Catalina\localhost\bigjava\org\apache\jsp\time_jsp.java:63:
cannot resolve symbol
symbol : class TimeFormatterBean
location: class org.apache.jsp.time_jsp
out.write(org.apache.jasper.runtime.JspRuntimeLibrary.toString((((Time
FormatterBean)_jspx_page_context.findAttribute("formatter")).getTime()
^
4 errors
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultError
Handler.java:83)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.
java:306)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:398)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:441)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:422)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.
java:507)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.
java:274)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:29
2)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
note The full stack trace of the root cause is available in the Apache
Tomcat/5.0.24 logs.
Apache Tomcat/5.0.24Cross Post
http://forum.java.sun.com/thread.jsp?thread=526883&forum=45&message=2528346 -
Setting and updating Date field in a jsp form
Hi:
I have a form (in jsp) where in I have a field for Date. The Date is entered in the form: 12/18/2002. I using beans to retrieve the form values and then pass to the program. THe date field is passed as String to the bean. The program changes the String to util date
(assignment ===> name of bean)
String strDate = assignment.getDueDate();
java.util.Date adate = null;
DateFormat fmt = DateFormat.getDateInstance(DateFormat.SHORT,Locale.US);
try {
adate = fmt.parse(strDate);
System.out.println("Util date in Bo: "+adate);
catch (ParseException e)
System.out.println(e);
and before inserting into database, it is changed from util.date to sql.date.
long time = adate.getTime();
java.sql.Date sqldate = new java.sql.Date(time);
Until now everythign is working fine. On my way back, when i retrieve the sql.date from the database, I change it to util date:
java.sql.Date sqlDate = rs.getDate("dueDate");
java.util.Date uDate = sqlDate;
and then covert this util date to String
String strDate = uDate.toString();
When I display this string date on my form... it is in the format
2002-12-18, although i have inserted it in 12/18/2002 format.
Can anyone help me since i want my date to appear on the form in the format I enter (12/18/2002) and not the 2002-12-18 format of databaseAlready answered elsewhere.
-
Please tell me the use of %! scriptlet in jsp
please tell me the use of <%! scriptlet in jsp
When the JSP is compiled to java normal scriptlet blocks are inserted inside the transaction processing method's code. <%! code goes outside the method, in the body of the generated class definition.
Typically you'd use it to define constants and private methods subsequently used in scriptlet code.
e.g. <%! private static final DateFormat df = new SimpleDate("dd/MM/yy"); %> -
Setting DateFormat when we update in SalesForce DB
Hi,
I want to set DateFormat before updating the date in
SalesForce Database. I am able to update the date if i select the
date/month which is greater than 9. Means If i select the date
10/10/2007 ([MM/DD/YYYY or DD/MM/YYYY format]) its
updating/inserting the data in SalesForce DB. if i select date
9/10/2007 it is not updateing why because In SalesForce DB it will
accept date/month in two digit format --> 09/10/2007 or
05/08/2007 but not 9/10/2007 or 5/8/2007. Is there any solutions to
set the dateformat using ActionScript before updating/Inserting the
date in SalesForce Database.
Thanks in advance<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by JDev Team ():
Hi,
I need to know some more details to know exactly why the field is not appearing.
1. Is this an attribute that was included in your EO when you first created it, or one that you added later?
ARCHANA : This attribute was not included later. It was there when I first created it because it is the "Code" which is the primary key.
2. Is this attribute in the View Object your JSP insert page is based on?
ARCHANA: Yes, It is there in the View Object.
3. Is the View Object your JSP insert page is based on made up of one EO, or is it based on more than one EO?
ARCHANA : The View Object is based on one EO only.
4. In your JSP, you can try adding the following code to see if the attribute field will get displayed:
<jsp:useBean id="RowEditor" class="oracle.jbo.html.databeans.EditCurrentRecord" scope="request">
<%
RowEditor.initialize(application, session , request, response, out, "theModule.theView");
RowEditor.setTargetUrl("theView_SubmitInsertForm.jsp");
RowEditor.createNewRow();
RowEditor.setReleaseApplicationResources(true);
RowEditor.setDisplayAttributes("Attr1,Attr2...");
(enter the names of the attributes you want displayed in the setDisplayAttributes method.
Laura<HR></BLOCKQUOTE>
Actually my JSP has exactly the same code as u have sent. I have included "Code" in my setDisplayAttributes() method also. The label for this attribute appears but adjacent to it there is no text control to type the data when I insert data.
Please explain.
null
Maybe you are looking for
-
About three days ago my iphone5 stopped connecting to my home wifi. I've tried everything in the trouble shooting guides and everything in all the support comments here.Ive reset network, reset all phone settings, turned wifi on and off, forgotten ne
-
Just finished a FCE (v 3.5.1) project on a Mac G-4 (OS 10.4.8) which included video and photo clips with audio sourced from the video clip or microphone. Exported to QT where both video and audio tracks were OK, then burned the DVD. On some DVD playe
-
Reg. Stock account instead of consumption account
Dear Experts Pls consider my below scenario When PR and PO creating material is posted to consumption account automatically,but our company needs to be posted stock account with account assignment category E. I am struggling for 6 months no one is gi
-
NW 7.3 Installation - Oracle Database connection issue.
Dear SDN, I am trying to install the SAP NW 7.3 but fail due the connection to oracle database. (My System details : Windows 7, 64 bit, 4gb ram - copyied NW7.3 server for 64 bit) I hvae installed the Oracle database and client. I have checked and sta
-
CRS Installation - Question regarding media pack
Hi all, I am waiting for the 10gR2 media pack to do a CRS install. When the media pack arrives, what CD/DVD should I start with? Any help would be appreciated. Thanks,