mahesh rao

Greenhorn
+ Follow
since Sep 08, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by mahesh rao

Hi,

I am new to Java development and to Spring framework. In my application, I need to send emails with HTML body. Also, there are many messages (HTML) that need to be displayed to the user on number of screens.

What is the recommended and efficient way to maintain different HTML text messages ? Is maintaining 'properties' file a good option ? I read an article that properties file should not be used for HTML text but only for plain text.

Thanks,
Mahesh
11 years ago
I tested the program again and it worked fine now. As you said, the window may have been hiding underneath all the other windows and I did not notice. Thanks.
12 years ago
I tried both in Eclipse and Netbeans. The issue persists. When I enter input other than 1, output is expected in JOptionPane Message Dialog box but nothing is displayed. Not sure if it is an issue with JDK 7.
12 years ago
The following program compiled fine and there are no runtime errors too. But it is not working the way I want. Can anyone please help.

When I enter input value as '1', it is displaying the output "ONE" as expected. When I enter any other value, nothing happens.

Is there a rule that JOptionPane showInputDialog method should be used for showMessageDialog to work ?
If I use JOptionPane showInputDialog method instead of InputStreamReader readLine method to get the input, the program starts working fine.
I am not sure why the program is not working properly if I use InputStreamReader readLine method for getting input and JOptionPane showMessageDialog method for displaying output.

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import javax.swing.JOptionPane;

public class SwitchTest {

public static void main(String[] args) {

BufferedReader dataIn = new BufferedReader (new InputStreamReader(System.in));

try {
System.out.println("Enter a number from 1 to 5:");
int dataInIntVal = Integer.parseInt(dataIn.readLine());

switch (dataInIntVal) {
case 1:
System.out.println("ONE");
break;
case 2:
JOptionPane.showMessageDialog(null, "TWO");
break;
case 3:
JOptionPane.showMessageDialog(null, "THREE");
break;
case 4:
JOptionPane.showMessageDialog(null, "FOUR");
break;
case 5:
JOptionPane.showMessageDialog(null, "FIVE");
break;
default:
JOptionPane.showMessageDialog(null, "You entered a different number");
break;
} //switch ends
} //try ends

catch (IOException e) {
System.out.println("ERROR! Invalid data.");
}

} //main method ends
}
12 years ago
I am not sure why the following does not work.

public class Test {
.....
}

class Test2 {
Test t;
t = new Test();
}

But this one works.

public class Test {
....
}

class Test2 {
Test t;

public void setup() {
t = new Test();
}
}

Can anyone explain it. Thanks.
15 years ago

Can anyone direct me to a Free and Simple JSP editor plugin for Eclipse.
16 years ago
JSP
I am getting today's date using java.util.Date and formatting using formatDate tag.

<jsp:useBean id="now" class="java.util.Date" />
<fmt:formatDate value="${now}" pattern="dd-MMM-yyyy" var="todayDate" />

However, when I display ${todayDate}, it is displaying differently for users depending on their system and browser settings.

For example, for a korean user, it displays 31-10?-2008 (notice the ? after month). For a sweden user, it displays 31-Okt-2008 (notice Okt instead of Oct).

Setting the locale and timezone on the page did not solve the problem.
<fmt:setLocale value='en-US' scope="page" />
<fmt:setTimeZone value='America/New_York' scope="page" />

What am I missing ?
16 years ago
JSP
Yes (pageScope is default scope). Thanks.
17 years ago
JSP
Thanks, that worked.
17 years ago
JSP
I have problem getting the result of a JSTL variable dynamically. Here is the scenario.
I have defined messages for some status values as follows in the page.

<c:set var="messagestatus1a" value="Less than 30 days with ME" /> <c:set var="messagestatus1b" value="30 days or more with ME" /> <c:set var="messagestatus2a" value="Less than 30 days with JPM"/> <c:set var="messagestatus2b" value="30 days or more with JPM" />

I get a status value from the database (such as status1a, status1b, status2a, status2b) and I am concatenating with 'message' so that I can frame the appropriate variable name.

<c:forEach var="suggestionsLoop" items="${suggestionQuery.rows}">
<c:set var="msgDesc" value="message${suggestionsLoop.status}" />
<!-- Now, 'msgDesc' variable has a value like 'messagestatus1a' or 'messagestatus1b' etc.,
I would like to reprocess the value from msgDesc to diaplay the appropriate message.
If I try ${${msgDesc}} obviously I am getting error. Any ideas how to accomplish this ?
-->
</c:forEach>

Thanks,
vmrao
17 years ago
JSP
OK. I finally got it to work.

I found that the server is using the cached version of web.xml from generated\xml\j2ee-modules\appName directory. I got rid of the appName directory and it fixed the problem.

Thanks
18 years ago
JSP
Here is my web.xml .

<?xml version="1.0" encoding="UTF-8"?>

<!--
Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
Use is subject to license terms.
-->

<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>testApp</display-name>
<distributable/>

<context-param>
<param-name>
myContextParamName
</param-name>
<param-value>
myContextParamValue
</param-value>
</context-param>

</web-app>

We are using Sun Java System Application Server 8.1 ENTERPRISE Edition.

I tested the same code with Sun Java Studio Enterprise 8 integrated with Sun Java System Application Server Professional edition and it works fine.
I am not sure why it is not working with ENTERPRISE edition on our server. Looks like web.xml is not being considered by the server. I deleted web.xml and still I was able to deploy the application successfully.
18 years ago
JSP
No output. As you know, JSTL does not show error on variables that do not exist. In this case, it was not able to find the context parameter defined in the web.xml file, I believe.
18 years ago
JSP
Hi,

I have the following code in web.xml for initialising context parameter.

<context-param>
<param-name>myContextParamName</param-name>
<param-value>myContextParamValue</param-value>
</context-param>

I am trying to access it in JSTL using
${initParam["myContextParamName"]}
and it does not work.

I am not sure if the changes to web.xml are being recognized. I tried to use a JNDI name that was set up on the server as a resource in web.xml and even that is not recognized by the code. Restarting the server did not help.

Any ideas please ?

Thanks
vmrao
18 years ago
JSP
Hi,

I created a JDBC resource called "jdbc/gms" under SUN JSAS admin. I am trying SQL query using JSTL tag in a JSP page as follows.

<sql:query var="learning" dataSource="jdbc/gms">
Query
</sql:query>

I am getting the error as DataSource invalid: "java.sql.SQLException: No suitable driver".

Instead, If I use the following code it is working properly.
<%
Connection connection = null;
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("jdbc/gms");
connection=ds.getConnection();
Statement stmt = connection.createStatement();
String sqlquery="My Query";
ResultSet rs = stmt.executeQuery(sqlquery);
%>

I am not sure why JSTL SQL Query is not working. Please help.