Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!

smitha rai

Ranch Hand
+ Follow
since Aug 15, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by smitha rai

Hi Tim,

Sorry I did not understand your question. Are there any specific settings to the IE?

9 years ago
Thanks for all who responded. Here is the complete code.

struts-config.xml
------------------
<action path="/pdf" type="demo.struts.action.BaseAction" name="saform" parameter="action">
<forward name="home" path="/pdf/home.jsp"/>
</action>

JSP
---
<%
String pdfurl3 = request.getContextPath() + "/pdf.do?action=displayPdf";
%>
Click
<a href="#" onClick="showPdf('<%=pdfurl3%>'); return false;">here to see the pdf file

javascript
----------
var theChild;
function showPdf(url) {
if(theChild!=null) {
if(getCurrentBrowserName() != 'msie') {
theChild.close();
}
}
theChild = popupPdf(url);
theChild.focus();
}

function popupPdf(url) {
alert('Attention: The document will be opened in another window. Please close window after printing or viewing!');
var attributes = 'menubar=no,toolbar=no,scrollbars=yes,resizable=yes,fullscreen=no';
attributes = attributes + ',width=' + (screen.availWidth - 150);
attributes = attributes + ',height=' + (screen.availHeight - 250);
attributes = attributes + ',screenX=50,screenY=50,left=10,top=10';
var wOpen;
wOpen = window.open(url, 'theChild', attributes);

//wOpen.focus();
wOpen.moveTo(75,50);
wOpen.resizeTo(screen.availWidth, screen.availHeight);

return wOpen;

}

function getCurrentBrowserName() {
var browserName = "";

var ua = navigator.userAgent.toLowerCase();
if ( ua.indexOf( "opera" ) != -1 ) {
browserName = "opera";
}
else if ( ua.indexOf( "msie" ) != -1 ) {
browserName = "msie";
}
else if ( ua.indexOf( "safari" ) != -1 ) {
browserName = "safari";
}
else if ( ua.indexOf( "mozilla" ) != -1 ) {
if ( ua.indexOf( "firefox" ) != -1 ) {
browserName = "firefox";
}
else {
browserName = "mozilla";
}
}
else {
browserName = "";
}

return browserName;
}

Action Class
------------
public class BaseAction extends DispatchAction {

public ActionForward displayPdf(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

String filepath = "/test/pdf/sample.pdf";

//For Local:
String baseFolder = "/Users/raghu/Documents/Shared/personal/Final_Out";

String contentType = getServlet().getServletContext().getMimeType(filepath);
response.setContentType(contentType);
//New
response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma", "public");

OutputStream out = response.getOutputStream();
byte[] pdfContent = this.loadFile(baseFolder + filepath);
out.write(pdfContent, 0, pdfContent.length);
if (out != null) {
out.close();
}

return null;
}

public static byte[] loadFile(String sourcePath) {
byte[] output = null;
InputStream inputStream = null;
try {
inputStream = new FileInputStream(sourcePath);
output = readFully(inputStream);
if (inputStream != null) {
inputStream.close();
}
}
catch(IOException ioex) {
//Handle Exception
}

return output;
}
}
9 years ago
Hi,

I am using struts DispatchAction to display the existing file (on the server) on the web browser. My code works on FireFox and Google Chrome. But displays empty screen when executed on IE. Please refer to the Action class and kindly help me out what am I missing in the code inorder to work on all browsers.

Page Access URL: http://localhost:8080/pdfWeb/showpdf.do?action=displayPdf

Action Class

9 years ago
Hi g tsuji,

Working great. Thanks a lot. Yes I am using XSLT 1.0.

Smitha
Hi,

I am a new to XSL programming. I have a requirement to add slash at every 4th character in a string. For example, a string value of 'abcdefghijklmn' to be translated to 'abcd/efgh/ijkl/mn'. Appreciate if someone help me out.

Regards,

Smitha
Hi,

I am trying to iterate the object stored in session using struts nested tag. I am getting an exception javax.servlet.jsp.JspException: Cannot find bean: "" in any scope. What am I missing in the following code. I do not want to have the Action class and action form bean. I have a need to access the session object and display the results. Here is my code and appreciate if some one helps me out.

Regards,

Smitha

JSP

<%@ taglib uri='/tags/struts-bean' prefix='bean' %>
<%@ taglib uri='/tags/struts-html' prefix='html' %>
<%@ taglib uri='/tags/struts-logic' prefix='logic' %>
<%@ taglib uri='/tags/struts-nested' prefix='nested' %>

<%
List<SubjectInfo> data = DataUtil.getData();
request.getSession().setAttribute("subjectInfo", data);
%>

<html>
<head>
<title>TabMenu Demo home</title>
</head>
<body>
<nested:iterate property="subjectInfo">
Subject: <nested:write property="name"/>

<nested:iterate property="topicInfo" >
Topic: <nested:write property="name"/>

Data: <nested:write property="data"/>
</nested:iterate>
</nested:iterate>
</body>
</html>

Helper Classes

public class SubjectInfo {
private String name;
private List<TopicInfo> topicInfo;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<TopicInfo> getTopicInfo() {
return topicInfo;
}
public void setTopicInfo(List<TopicInfo> topicInfo) {
this.topicInfo = topicInfo;
}
}

public class TopicInfo {

private String name;
private String data;

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
}

public class DataUtil {

public List<SubjectInfo> getTestData() {
List<SubjectInfo> subjects = new ArrayList<SubjectInfo>();

//First Subject
SubjectInfo subject = new SubjectInfo();
subject.setName("Maths");
List<TipocInfo> topics = new ArrayList<TopicInfo>();
TopicInfo topic = new TopicInfo();
topic.setName("Addition");
topic.setData("Data for addition");
topics.add(topic);
//Second topic
topic = new TopicInfo();
topic.setName("Subtraction");
topic.setData("Data for subtraction");
topics.add(topic);
subject.setTopicInfo(topics);
subjects.add(subject);

//Second Subject
subject = new SubjectInfo();
subject.setName("English");
topics = new ArrayList<TopicInfo>();
topic = new TopicInfo();
topic.setName("Adjectives");
topic.setData("Data for adjectives");
topics.add(topic);
subject.setTopicInfo(topics);
subjects.add(subject);

return subjects;
}
10 years ago
I have a datasource (jdbc/hibernatespring) configured on the websphere server. I am able to get connection while executing the JSPs (which intenally calls the DAOs) and display the contents appropriately.

I have written JUnit test cases for the DAOs and while executing the test cases, it could not be able to find the datasource and throws "NoInitialContextException" exception. In this scenario, definitely the test cases are executed in a different JVM. How to get the hibernate session in such scenario?


hibernate.cfg.xml
========================================================================
<hibernate-configuration>

<session-factory name="java:hibernate/SessionFactory">
<property name="connection.datasource">jdbc/hibernatespring</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="show_sql">false</property>

<!-- Add the resource config files here-->
<mapping resource="user.hbm.config.xml"/>
<mapping resource="insurance.hbm.config.xml"/>
</session-factory>

</hibernate-configuration>

==========================================================================
I am using the following code to get the hibernate session
public Session getHibernateSession() {

SessionFactory sessionFactory =
new Configuration()
.configure("hibernate.cfg.xml")
.buildSessionFactory();
Session session = sessionFactory.openSession();

return session;
}

============================================================================
The exception is:

[FATAL] DatasourceConnectionProvider - Could not find datasource: jdbc/hibernatespring <javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial>javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:652)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:255)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:292)
at javax.naming.InitialContext.lookup(InitialContext.java:359)
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:44)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:80)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:362)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:60)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1463)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1004)
at demo.client.HibernateClient.getHibernateSession(HibernateClient.java:46)
at demo.client.select.user.UserSelectClient.readData(UserSelectClient.java:35)
at demo.client.select.user.UserSelectClient.main(UserSelectClient.java:56)

org.hibernate.HibernateException: Could not find datasource
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:48)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:80)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:362)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:60)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1463)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1004)
at demo.client.HibernateClient.getHibernateSession(HibernateClient.java:46)
at demo.client.select.user.UserSelectClient.readData(UserSelectClient.java:35)
at demo.client.select.user.UserSelectClient.main(UserSelectClient.java:56)
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:652)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:255)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:292)
at javax.naming.InitialContext.lookup(InitialContext.java:359)
Hi Gurus,

What is locale and how it is used while retrieving the data from the database?

Thanks,

Smitha
16 years ago
Hello,

I need to check the given object array is an instance of string array or not. Please refer to the following code. When the code is executed the control never goes into the if loop (if(objArray instanceof String[])). What am I missing here? Secondly when I try to cast the object array to a string array, I get class cast exception. Please help me out.

Thanks,

Smitha

public class TestString {

public static void main(String[] args) {
String[] strArray = new String[] { "one", "two" };
Object[] objArray = new Object[] { "one1", "two2" };

System.out.println("From string array: " + (String) strArray.toString());
System.out.println("From object array: " + (String) objArray.toString());

if(objArray instanceof String[]) {
//Never enters into this loop
for(int i=0; i<objArray.length; i++) {
System.out.println(objArray[i]);
}
} else {
System.out.println("Failed");
}
//Fails here - java.lang.ClassCastException: java.lang.Object
String[] strArray1 = (String[]) objArray;
}
}
16 years ago
Hi,

Is there any sample java code that would set the values (val1, val2, val3). I am using following in my log4j configuration file.

log4j.appender.R5.layout.ConversionPattern=INSERT INTO Logs (Date, val1, Val2, val3) VALUES ('%d', 'val1', 'val2', 'val3')

Thanks,

Smitha
Hi Gurus,

I am trying to log the error message generated by a java code into the database using log4j. If someone has a sample java code and log4j configuration parameters, appreciate if you could provide the same.

Regards,

Smitha
Hi,
I have a PL-SQL function that returns a string. The return string contains two strings separated by a unicode character (example AA�BB). My code returns AB\u00fdBB instead of AA�BB. How to insert a unicode character in PLSQL? My code is as under. M
Appreciate if some one helps me out in this regard.
Thanks in advance,
Smitha
============================================================================
FUNCTION getValue(strA VARCHAR2, strB VARCHAR2)RETURN VARCHAR2
AS
v_unicode VARCHAR2(10) := '\u00fd';
v_out VARCHAR2(50);
BEGIN
v_out strA || v_unicode || strB;
DBMS_OUTPUT.PUT_LINE(v_out);
RETURN v_out;
END getValue;
Hi,
I am trying to insert a clob data and i am getting the error "ORA-01002: fetch out of sequence". Appreciate if some one could help me correcting my code. My code is as under:
Smitha
===========================================================================
package org.kp.fep2.purchasing;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import oracle.sql.CLOB;
import org.kp.j2ee.db.DBUtil;
public class WriteLOB
{
String c_strSQL
= "SELECT contents_clob FROM requisition_t WHERE requisition_t.req_ik = 2000001 FOR UPDATE";
public void writeCLOB()
{
String strTestData = "This is a sample text";
Connection oConn = null;
PreparedStatement pstmt = null;
Statement stmt = null;
ResultSet rsData = null;
char[] cbuf = new char[strTestData.length()];
strTestData.getChars(0, strTestData.length(), cbuf, 0);

try
{
oConn = getConnection();
stmt = oConn.createStatement();
rsData = stmt.executeQuery(c_strSQL);
rsData.next();
CLOB oClob = (CLOB) rsData.getClob(1);
Writer oClobWriter = oClob.getCharacterOutputStream();
oClobWriter.write(cbuf);
oClobWriter.close();
oConn.commit();
}
catch(Exception ex)
{
System.out.println("***************** Exception in writing data : " + ex.getMessage());
}
finally
{
DBUtil.closeAll(rsData, pstmt, oConn);
}
} //writeBLOB
public String readCLOB()
{
Connection oConn = null;
PreparedStatement pstmt = null;
ResultSet rsData = null;
StringBuffer sbData = null;

try
{
oConn = getConnection();
pstmt = oConn.prepareStatement(c_strSQL);
pstmt.setString(1, "2000001");
rsData = pstmt.executeQuery();
rsData.next();
CLOB oClob = (CLOB) rsData.getClob(1);

Reader oClobReader = oClob.getCharacterStream();
sbData = new StringBuffer();
int nChars = 0;
char[] cbuf = new char[10];
while((nChars = oClobReader.read(cbuf)) != -1)
{
sbData.append(cbuf, 0, nChars);
}
oClobReader.close();
}
catch(Exception ex)
{
System.out.println("***************** Exception in reading data : " + ex.getMessage());
}
finally
{
DBUtil.closeAll(rsData, pstmt, oConn);
}

return sbData.toString();
} //readCLOB

public Connection getConnection()
{
Connection oConn = null;
try
{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
oConn = DriverManager.getConnection ("jdbc racle:thin:@8i", "scott", "tiger");
System.out.println("******** Connection established");
}
catch(Exception ex)
{
System.out.println("******** Connection failed");
}
return oConn;
}

public static void main(String[] args)
{
WriteLOB oLob = new WriteLOB();
oLob.writeCLOB();
System.out.println("**** the data is: " + oLob.readCLOB());
}
}
ava Gurus,
I need to add an octal 253 character in between a text string. I am not sure how do I acheive this. It would be a great help if someone helps me out in this regard. My code is as under:
Thanks,
Smitha
_________________________________________________________________________
public class OctalTest {
public String getFinalString() {
return "First String" + octal 253 + "Second String";
}
public static void main(String[] args) {
OctalTest ot = new OctalTest;
System.out.println("The Final String is: " + ot.getFinalString());
}
}
17 years ago
Hi Java Gurus,
I need to add an octal 253 character in between a text string. I am not sure how do I acheive this. It would be a great help if someone helps me out in this regard. My code is as under:
Thanks,
Smitha
_________________________________________________________________________
public class OctalTest {
public String getFinalString() {
return "First String" + octal 253 + "Second String";
}

public static void main(String[] args) {
OctalTest ot = new OctalTest;
System.out.println("The Final String is: " + ot.getFinalString());
}
}
17 years ago