as chhipa

Greenhorn
+ Follow
since Sep 04, 2006
Merit badge: grant badges
For More
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 as chhipa

Dear all,
I read in books that Class.forName("driverClass") loads the jdbc driver in java virtual machene and Driver.getConnection("url") establishes connection to the database.

My question is if I have two jdbc programs to interact with the same database why do I need to Class.forName("driverClass") in both the programs.
Instead I could use Class.forName("driverClass") in first program and Driver.getConnection("url") in both the programs because the driver class is already loaded in the JVM through the first program.
Hi all,
I'm new to struts. Previously I used FrontPage to create static HTML pages and after this would insert neccessary tags and code in the page and convert it to JSP. But since I switched to struts I don't know how to do it all. First FrontPage does not support struts so I' cant create page layout and see preview. Secodly creating various configuration xml files in notepad is a daunting task in itself.
Can you guys suggest any IDE which can address my both of these concerns.
Thanks.
17 years ago
Hi all,
I' using struts 1.3.5 with tomcat 5.0.28 and jdk1.4.2. Although my application is working fine but when I look at tomcat console I get follwing warnings on failure of any validation rules.

WARNING: REsource org/apache/struts/ validator/ LocalStrings_en_US.properties Not Foundsd
WARNING: REsource org/apache/struts /validator/ LocalStrings_en.properties Not Found

I have folwing files in WEB-INF directory

ApplicationResources_it_CH.properties
ApplicationResources_en_US.properties
application_it_CH.properties
application_en_US.properties

The language setting in Internet Explorer is as follwing
English(United States)[en-us]
Italian(Switzerland)[it-ch]
--------------------------------------------------
web.xml is follwing

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 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"
version="2.4">

<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>application</param-name>
<param-value>ApplicationResources</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<taglib>
<taglib-uri>struts-html</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-html-el.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>struts-bean</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>struts-logic</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-logic-el.tld</taglib-location>
</taglib>

</web-app>

-----------------------------------------------------
struts-config.xml is as follwing

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
<form-beans>
<form-bean name="inputFormTwoStep" type="ch03.InputWorkflowForm" />
</form-beans>
<action-mappings>
<action path="/inputSubmitStep1" type="ch03.InputWorkflowAction" name="inputFormTwoStep" validate="true" scope="session" parameter="method12" input="/step1.jsp">
<forward name="success" path="/step2.jsp" />
</action>

<action path="/inputSubmitStep2" type="ch03.InputWorkflowAction" name="inputFormTwoStep" validate="true" scope="session" parameter="method12" input="/step2.jsp">
<forward name="success" path="/success.jsp" />
</action>
</action-mappings>
<message-resources parameter="application" />
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />
</plug-in>
</struts-config>
-------------------------------------------------------------
validation.xml is as follwing

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.3.0//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_3_0.dtd">
<form-validation>

<formset>

<form name="inputForm">

<field property="userName" depends="minlength">
<arg key="inputForm.userName" resource="true" position="0"/>
<arg name="minlength" key="${var:minlength}" resource="false"
position="1"/>
<var>
<var-name>minlength</var-name>
<var-value>5</var-value>
</var>
</field>

</form>

<form name="inputFormTwoStep">

<field property="userName" depends="required,minlength,maxlength" page="0">
<arg key="inputForm.userName" resource="true" position="0"/>
<arg name="minlength" key="${var:minlength}" resource="false" position="1"/>
<arg name="maxlength" key="${var:maxlength}" resource="false" position="2"/>
<var>
<var-name>minlength</var-name>
<var-value>5</var-value>
</var>
<var>
<var-name>maxlength</var-name>
<var-value>11</var-value>
</var>
</field>

<field property="website" depends="required" page="1">
<arg key="inputForm.website" resource="true" position="0"/>
</field>

</form>

</formset>

</form-validation>
17 years ago
Hi all,
I have found the solution.Actually I'm using struts 1.3.5. and in this case culprit is validation.xml file.

Previously my validation.xml file was as follwing which is used in the older version

<form name="inputForm">

<field property="userName" depends="minlength">
<arg0 key="inputForm.userName" resource="true" />
<arg1 name="minlength" key="${var:minlength}" resource="false" />
<var>
<var-name>minlength</var-name>
<var-value>5</var-value>
</var>
</field>

</form>


but in struts 1.3.5 it will be like this
(Pay attention to arg element and position attribute )

<form name="inputForm">

<field property="userName" depends="minlength">
<arg key="inputForm.userName" resource="true" position="0"/>
<arg name="minlength" key="${var:minlength}" resource="false"
position="1"/>
<var>
<var-name>minlength</var-name>
<var-value>5</var-value>
</var>
</field>

</form>
17 years ago
Thank you for your reply but setting

validate="true"

is not making any difference.
17 years ago
Hi all,
I'm new to struts and wants to validate my form field in input.jsp for the minlength. If the length is less than 5 then the control must return back to the input.jsp other wise it must go to success.jsp.
But at present what happening that if user enters less than 5 character than also the success.jsp page is being displayed instead of input.jsp.


Follwing is the struts-config file

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config
PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<global-forwards>
<forward name="home" path="/home.do" />
</global-forwards>
<form-beans>
<form-bean name="lookupForm" type="ch03.LookupForm" />
<form-bean name="inputForm" type="ch03.InputForm" />
</form-beans>

<action-mappings>
<action path="/lookup" type="ch03.LookupAction" name="lookupForm" >
<forward name="success" path="/quote.jsp" />
<forward name="failure" path="/index.jsp" />
</action>
<action path="/inputSubmit" type="ch03.InputAction" name="inputForm" scope="request" validate="false" input="/input.jsp" >
<forward name="success" path="/success.jsp" />
</action>
<action path="/home" forward="/quote.jsp" />

</action-mappings>
<message-resources parameter="ApplicationResources" />
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml, /WEB-INF/validation.xml" />
</plug-in>

</struts-config>
--------------------------------------------------------------------

Follwing is the input.jsp page

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html>
<body>
<logic:messagesPresent>
There were error
<ul>
<font color='red'>
<html:messages id="error" >
<li><%=error %></li>
</html:messages>
</font>
</ul>
</logic:messagesPresent>
<html:form action="inputSubmit">
<bean:message key="inputForm.userName" />
<html:text property="userName" /> <br/>
<html:submit value="ok" />
</html:form>
</body>
</html>

---------------------------------------------------------

Follwing is InputForm.java

package ch03;

import org.apache.struts.action.ActionForm;
import org.apache.struts.validator.ValidatorForm;
public class InputForm extends ValidatorForm
{
public String userName;
public String getUserName()
{
return userName;
}
public void setUserName(String string)
{
userName=string;
}
}
----------------------------------------------------
Following is InputAction.java

package ch03;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForward;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class InputAction extends Action
{
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception
{
InputForm inputForm=(InputForm)form;
System.out.println(inputForm.getUserName());
return mapping.findForward("success");
}
}
--------------------------------------------------------------------

and follwing is snippet from validation.xml file

<form name="inputForm">
<field property="userName"
depends="minlength">
<arg0 key="inputForm.userName" />
<arg1 key="$(var:minlength)"
name="minlength"
resource="false" />
<var>
<var-name>minlength</var-name>
<var-value>5</var-value>
</var>
</field>
</form>
17 years ago
Hi everybody,
I create struts plugin from Profession Jakarta Struts 1.1. I also have replaced ApplicationConfig with ModuleConfig as ApplicationConfig has been deprecated. After the changes my program is as follwing

package ch03;
import java.util.Properties;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.ServletContext;

import org.apache.struts.action.PlugIn;
//import org.apache.struts.config.ApplicationConfig;
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.action.ActionServlet;

public class WroxPlugin implements PlugIn
{
public WroxPlugin(){}
public void init(ActionServlet servlet, ModuleConfig applicationConfig) throws javax.servlet.ServletException
{
System.out.println("--------The Plugin is starting");
Properties properties =new Properties();
try
{
File file=new File("db.properties");
FileInputStream fis=new FileInputStream(file);
properties.load(fis);
ServletContext context=servlet.getServletContext();
context.setAttribute("PROPERTIES",properties);

}
catch(FileNotFoundException fnfe)
{
throw new ServletException(fnfe.getMessage());
}
catch(IOException ioe)
{
throw new ServletException(ioe.getMessage());
}
}
public void destroy()
{
System.out.println("----- THe Plugin is stopping------");
}
}


plug in entry in struts-config file is as follwing

<plg-in className="ch03.WroxPlugin" />

But when I restart the tomcat and start the application I dont find the --------The Plugin is starting message on Tomcat console.

The tomcat version is 4.1.31
THe java version is j2sdk1.4.2

Can any body suggest any alternative to call the plaugin init method
Thanks
17 years ago
Hi everybody,
Currently I am using JasperReport for printing. I want to show message to the user when the reoprt has been printed. At the moment what is hapening that as soon as the program submit the report to printer it shows the message that report has been printed even though it is still being printed or in the printer queue.
I want to show this message only after the work has been done on the printer side.

Following is my code snippet

jasperReport = JasperCompileManager.compileReport("ClubFiles\\repschema.jrxml");

jasperPrint = JasperFillManager.fillReport(jasperReport, m, new JREmptyDataSource());

JasperPrintManager jasperPrintManager = new JasperPrintManager();
jasperPrintManager.printReport(jasperPrint,false);

System.out.println("report printed");
17 years ago
Hi every body,
I have a weird problem. Follwing is the code snippet for printitng.
try
{

JasperReport jasperReport;
JasperPrint jasperPrint;
Map m= new HashMap();
m.put("reportTitle", printList.get(i));
JOptionPane.showMessageDialog(ClubAmtFrame.this,"before compile","Error",JOptionPane.ERROR_MESSAGE);
jasperReport = JasperCompileManager.compileReport("C:\\j2sdk1.4.2\\bin\\ClubFiles\\jasperreports_demo.jrxml");

JOptionPane.showMessageDialog(ClubAmtFrame.this,"after compile","Error",JOptionPane.ERROR_MESSAGE);
//jasperPrint = JasperFillManager.fillReport(jasperReport, m, new JREmptyDataSource());
//JasperPrintManager jasperPrintManager = new JasperPrintManager();
//jasperPrintManager.printReport(jasperPrint,false);
catch(Exception e)
{
JOptionPane.showMessageDialog(ClubAmtFrame.this,e.toString(),"Error",JOptionPane.ERROR_MESSAGE);
}


My problem is that when I run the above program from console without making the executable .jar file , this code works fine(all commented statements also executed). But when I make executable .jar file the above code does not work, neither it throws any exception.THe path of the .jrxml is all correct.
I'm trying to print contents of notepad file. For this I have filled the JTextArea with the contents of File. The font type of both JtextArea and notepad file is Courier New and Size Font Size is 14.I am passing the JTextArea to the printComponent method.
My problem is that when I try to print the notepad files which I receive from other system automatically the font size issmallest(probably 2 inch).
But now I make the same file manully and try to print then there is no problem. I can not understand why there is font-descripancy.

One more thing If I use Times New Roman, there is no problem. But I can't use that because it misalign the contents of the auto-generated file.

Following is my program,

import java.awt.*;
import javax.swing.*;
import java.awt.print.*;

public class PrintUtilities implements Printable {
private Component componentToBePrinted;

public static void printComponent(Component c) {
new PrintUtilities(c).print();
}

public PrintUtilities(Component componentToBePrinted) {
this.componentToBePrinted = componentToBePrinted;
}

public void print() {
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(this);
if (printJob.printDialog())
try {
System.out.println("Calling PrintJob.print()");
printJob.print();
System.out.println("End PrintJob.print()");
}
catch (PrinterException pe) {
System.out.println("Error printing: " + pe);
}
}

public int print(Graphics g, PageFormat pf, int pageIndex) {
int response = NO_SUCH_PAGE;

Graphics2D g2 = (Graphics2D) g;

// for faster printing, turn off double buffering
disableDoubleBuffering(componentToBePrinted);

Dimension d = componentToBePrinted.getSize(); //get size of document
double panelWidth = d.width; //width in pixels
double panelHeight = d.height; //height in pixels

double pageHeight = pf.getImageableHeight(); //height of printer page
double pageWidth = pf.getImageableWidth(); //width of printer page

double scale = pageWidth / panelWidth;
int totalNumPages = (int) Math.ceil(scale * panelHeight / pageHeight);

// make sure not print empty pages
if (pageIndex >= totalNumPages) {
response = NO_SUCH_PAGE;
}
else {

// shift Graphic to line up with beginning of print-imageable region
g2.translate(pf.getImageableX(), pf.getImageableY());

// shift Graphic to line up with beginning of next page to print
g2.translate(0f, -pageIndex * pageHeight);

// scale the page so the width fits...
g2.scale(scale, scale);

componentToBePrinted.paint(g2); //repaint the page for printing

enableDoubleBuffering(componentToBePrinted);
response = Printable.PAGE_EXISTS;
}
return response;
}

public static void disableDoubleBuffering(Component c) {
RepaintManager currentManager = RepaintManager.currentManager(c);
currentManager.setDoubleBufferingEnabled(false);
}

public static void enableDoubleBuffering(Component c) {
RepaintManager currentManager = RepaintManager.currentManager(c);
currentManager.setDoubleBufferingEnabled(true);
}
}
17 years ago
Hi every body,
I have to print text file. Can you tell me how to specify the inputstream in jrxml file for reading the file and sending the data on printer
17 years ago
Follwing is my program for printing the contents on Epson LX-300 Dot-Matrix Printer


-------------------------------------
I'm getting follwing exception

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at FilePrinterMain.main(FilePrinterMain.java:29)


at the line

System.out.println("len="+services[0].getName());
-----------------------------------------------
Operating System -------Windows 2000 Server
Printers

HP LaserJet 4000 Series PCL (Network Printer but currently unplaugged but mapped on my system)

Epson LX-300 (Local Printer which I'm currently using)

Print API:- Print API embeded with NetBeans IDE 5.0

[ Edited to include code tags - Paul Sturrock ]
[ November 17, 2006: Message edited by: Paul Sturrock ]
17 years ago
Hi everybody,
Follwing is my problem.
I'm generating some text files. the numbers of files is not fixed. it varies depending on certain conditions.
No what i have to do is that I have to print the contents of those text files. Can you tell me how can we do it. I think it can be done using JasperReport but I'don't have any clue how to start.
One thing is important that I don't have to look any preview of the report I have to simply print the text files on printer.
Thank you.
17 years ago
Hi everybody
I am getting follwing exception when open the index.jsp page


javax.servlet.ServletException: Cannot find ActionMappings or ActionFormBeans collection
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:495)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:70)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:92)
...
....
-----------------------------------------------------

Tomcat version---------> jakarta-tomcat-4.1.31
Java Version ---------> j2sdk1.4.2


Follwing is index.jsp page


<%@ page language="java" %>
<%@taglib
uri="/WEB-INF/struts-html.tld"
prefix="html" %>
<html>
<body>
<html:form action="lookup">
<table width="45%" border="0">
<tr>
<td>Symbol:</td>
<td><html:text property="symbol" /></td>
</tr>
<tr>
<td colspan="2" align="center"><html:submit /></td>
</tr>
</table>
</html:form>
</body>
<html>
-------------------------------------------------------------------------

Follwing is web.xml



<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<display-name>Tomcat Examples</display-name>
<description>
Tomcat Example servlets and JSP pages.
</description>


<servlet>
<servlet-name>action</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>

</web-app>

-------------------------------------------------
Folwing is struts-config.xml

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config
PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<form-beans>
<form-bean name="lookupForm" type="ch03.LookupForm" />
</form-beans>
<action-mappings>
<action path="/lookup" type="ch03.LookupAction" name="lookupForm" >
<forward name="success" path="/quote.jsp" />
<forward name="failure" path="/index.jsp" />
</action>
</action-mappings>
</struts-config>
--------------------------------------------------------------------------
Jar Files included in the WEB-INF/lib folder
commons-fileupload-1.0.jar
struts.jar
commons-beanutils.jar
commons-collections.jar
commons-dbcp-1.1.jar
commons-digester.jar
commons-logging.jar
commons-pool-1.1.jar
commons-validator.jar
jakarta-oro.jar
antlr.jar
17 years ago
Hi every body,
Probably it is not appropriate forum to address my problem but I do not know where to put this problem.

My problem is like this:

I have A4 size paper on which I have to print multiple reports of the size 5' * 5'(inch)
Can any body suggest how can i implement other tools like JasperReport etc.