Html file throw protal
hi all.
i have a little problem:
i upload html file in portal and it is look like this
http://your:port/pls/mydocs/mydocs.content_pkg.download?p_file=F920058486/index.shtml
if i clicked on inside ref i see eror
The requested URL /pls/mydocs/index.shtml was not found on this server.
i know why:
inside refs in this file look like this
http://your:port/pls/mydocs/index.shtml#1
http://your:port/pls/mydocs/index.shtml#2...
but inside refs should be
http://your:port/pls/mydocs/mydocs.content_pkg.download?p_file=F920058486/index.shtml#1
i don't know how to do it.
thanks
Jason
If you need to use xmodem then there is probably more to this situation than you have told us so far. Knowing more of the background might help us to give you better advice.
I doubt that you will be able to successfully use xmodem to copy files which would support HTML and the Web Console. If you are using xmodem then you are almost certainly copying a bin file. If that copy is successful it should allow you to use the command line for access. And through the archive command you can copy the tar file and install the HTML files to use the Web Console.
HTH
Rick
Similar Messages
-
Getting links and its names from a html file
Hi everyone
My problem about the a getting links with name from a html file. For example
İn a web page in this site ?SUN? when use click SUN the browser open http://java.sun.com
İ want both of them, so the links and name. I can succeeded the get link but i don t know how to get the link name.
For example :
<B>setRightComponent(Component)</B>
İn this code segment i want to get B tag. But how i don t know. To get A tag i used this code
List result = new ArrayList();
try {
// Create a reader on the HTML content
URL url = new URI(uriStr).toURL();
URLConnection conn = url.openConnection();
Reader rd = new InputStreamReader(conn.getInputStream());
// Parse the HTML
EditorKit kit = new HTMLEditorKit();
HTMLDocument doc = (HTMLDocument)kit.createDefaultDocument();
kit.read(rd, doc, 0);
// Find all the A elements in the HTML document
HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
while (it.isValid()) {
SimpleAttributeSet s = (SimpleAttributeSet)it.getAttributes();
String link = (String)s.getAttribute(HTML.Attribute.HREF);
if (link != null) {
result.add(link);
it.next();
İ can use B tag but i don t know hot to get its value because it has no prefix such as HREF....
i am sorry if i use a bad explanation style or incorrect word.import java.io.*;
import java.net.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
class GetLinks
public static void main(String[] args)
throws Exception
// Create a reader on the HTML content
Reader reader = getReader( args[0] );
// Parse the HTML
EditorKit kit = new HTMLEditorKit();
HTMLDocument doc = (HTMLDocument)kit.createDefaultDocument();
doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
kit.read(reader, doc, 0);
// Find all the A elements in the HTML document
HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
while (it.isValid())
SimpleAttributeSet s = (SimpleAttributeSet)it.getAttributes();
String href = (String)s.getAttribute(HTML.Attribute.HREF);
int start = it.getStartOffset();
int end = it.getEndOffset();
String text = doc.getText(start, end - start);
System.out.println( href + " : " + text );
it.next();
// If 'uri' begins with "http:" treat as a URL,
// otherwise, treat as a local file.
static Reader getReader(String uri)
throws IOException
// Retrieve from Internet.
if (uri.startsWith("http:"))
URLConnection conn = new URL(uri).openConnection();
return new InputStreamReader(conn.getInputStream());
// Retrieve from file.
else
return new FileReader(uri);
} -
Print HTML file inside JEditorPane
Hi Guys,
I'm trying to print the contents of a JEditorPane - actually, a html file that I read and display in that component from the underlying file system. I've had the class that manages the JEditorPane implement Printable - the following is my print() implementation:
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
throws PrinterException {
if (pageIndex > 0) {
return (NO_SUCH_PAGE);
} else {
Graphics2D g2d = (Graphics2D) graphics;
g2d.translate(
pageFormat.getImageableX(),
pageFormat.getImageableY());
ivTextArea.paint(g2d);
return (PAGE_EXISTS);
}I've got another method that gets called when a print button is clicked:
class .... {
PrintJob pj;
PageFormat pf;
private void printMe() {
if (pj == null) {
pj = PrinterJob.getPrinterJob();
pf = pj.defaultPage();
pf.setOrientation(PageFormat.PORTRAIT);
pf = pj.pageDialog(pf);
pj.setPrintable(this, pf);
try {
pj.print();
} catch (PrinterException e) {
throw new RuntimeException(e);
}Clearly I'm doing smth wrong, since only a single page gets printed and moreover the formatting is awful [text gets cut instead of moving on the next line]. Can someone help?
Thanks much!if (pageIndex > 0) {
return (NO_SUCH_PAGE);This is why you only get a single page.
page gets printed and moreover the formatting is
awful [text gets cut instead of moving on the next
line]. Can someone help?Yeah. Your best bet is either to put the editorpane in a scrollpane and just print what's visible, OR, you can take the print graphics object, convert it into a graphics2D object, and call scale on that by comparing component.getWidth/height to PageFormat.getImageableWidth/Height
I'm attaching my StandardPrint class. It uses the pageable interface to carry the number of pages + page format as well. I'm not sure if I did the scaling here or not, but I've done it before so I know it works :-) Also, I've got methods for previewing the print, which can save a lot of paper.
Please feel free to have and use this class, but please do not change the package or portray this as your own work
=============================
package tjacobs.print;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.print.*;
import javax.print.PrintException;
public class StandardPrint implements Printable, Pageable {
Component c;
SpecialPrint sp;
PageFormat mFormat;
public StandardPrint(Component c) {
this.c = c;
if (c instanceof SpecialPrint) {
sp = (SpecialPrint)c;
public StandardPrint(SpecialPrint sp) {
this.sp = sp;
public void start() throws PrinterException {
PrinterJob job = PrinterJob.getPrinterJob();
if (mFormat == null) {
mFormat = job.defaultPage();
job.setPageable(this);
if (job.printDialog()) {
job.print();
public void setPageFormat (PageFormat pf) {
mFormat = pf;
public void printStandardComponent (Pageable p) throws PrinterException {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPageable(p);
job.print();
private Dimension getJobSize() {
if (sp != null) {
return sp.getPrintSize();
else {
return c.getSize();
public static Image preview (int width, int height, Printable sp, PageFormat pf, int pageNo) {
BufferedImage im = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
return preview (im, sp, pf, pageNo);
public static Image preview (Image im, Printable sp, PageFormat pf, int pageNo) {
Graphics2D g = (Graphics2D) im.getGraphics();
// PageFormat pf = sp.getPageFormat(pageNo);
// int width = im.getWidth(null);
// int height = im.getHeight(null);
// g.setColor(Color.WHITE);
// g.fillRect(0, 0, width, height);
// double hratio = height / pf.getHeight();
// double wratio = width / pf.getWidth();
// g.scale(hratio, wratio);
try {
sp.print(g, pf, pageNo);
catch(PrinterException pe) {
pe.printStackTrace();
g.dispose();
return im;
public int print(Graphics gr, PageFormat format, int pageNo) {
mFormat = format;
Graphics2D g = (Graphics2D) gr;
g.translate((int)format.getImageableX(), (int)format.getImageableY());
Dimension size = getJobSize();
if (pageNo > getNumberOfPages()) {
return Printable.NO_SUCH_PAGE;
int horizontal = getNumHorizontalPages();
int vertical = getNumVerticalPages();
int horizontalOffset = (int) ((pageNo % horizontal) * format.getImageableWidth());
int verticalOffset = (int) ((pageNo / vertical) * format.getImageableHeight());
double ratio = getScreenRatio();
g.scale(1 / ratio, 1 / ratio);
g.translate(-horizontal, -vertical);
if (sp != null) {
sp.printerPaint(g);
else {
c.paint(g);
g.translate(horizontal, vertical);
g.scale(ratio, ratio);
g.translate((int)-format.getImageableX(), (int)-format.getImageableY());
return Printable.PAGE_EXISTS;
public int getNumHorizontalPages() {
Dimension size = getJobSize();
int imWidth = (int)mFormat.getImageableWidth();
int pWidth = 1 + (int)(size.width / getScreenRatio() / imWidth) - (imWidth == size.width ? 1 : 0);
return pWidth;
private double getScreenRatio () {
double res = Toolkit.getDefaultToolkit().getScreenResolution();
double ratio = res / 72.0;
return ratio;
public int getNumVerticalPages() {
Dimension size = getJobSize();
int imHeight = (int)mFormat.getImageableHeight();
int pHeight = (int) (1 + (size.height / getScreenRatio() / imHeight)) - (imHeight == size.height ? 1 : 0);
return pHeight;
public int getNumberOfPages() {
return getNumHorizontalPages() * getNumVerticalPages();
public Printable getPrintable(int i) {
return this;
public PageFormat getPageFormat(int page) {
if (mFormat == null) {
PrinterJob job = PrinterJob.getPrinterJob();
mFormat = job.defaultPage();
return mFormat;
}>
Thanks much! -
Reading in HTML file then writing to file - losing formatting.
I am reading in a HTML file using a Buffered Reader then writing it to a file. However when i write it to a file using
out = new PrintWriter(new BufferedWriter(new FileWriter(path, true)));
out.write(content);
out.flush();
i seem to lose all carriage returns and find that the whole html is on one single line with the only noticable formatting being the spaces between the html tags.
How can i stop it losing carriage returns?You only showed the part where you are writing it out.
Does your reader code look like this:
BufferedReader r = ...
String content = "";
while (true) {
String line = r.readLine();
if (line == null) break;
content += line;
}If it does, the problem lies here, as doing a readLine removes the line terminator. Soooo....
content += line + "\n";Of course, to be most efficient and good, don't use String concatenation, use a StringBuffer (though it should be noted that when I decompiled this test code, suns compiler did indeed use a StringBuffer).
When you print, use the PrintWriter methods print and priintln as they don't throw exceptions. -
How to run an applet(in a html file) in the server?
I am using the jpedal Viewer inmy code, I embedded the applet code
in a html file , it is running fine, but when I try to run the same Viewer applet in the Server it is throwing an error
"java.lang.NoClassDefFoundError: org/jpedal/objects/acroforms/DefaultAcroRenderer
at org.jpedal.PdfDecoder.startup(Unknown Source)
at org.jpedal.PdfDecoder.<init>(Unknown Source)
at pdfViewer.PdfApplet.init(PdfApplet.java:199)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)"
What is the problem ?
Please suggest solution for it?
Its urgentI am trying to run the Applet in Tomcat server,
Could you post the code where you invoke the Applet? It sounds like you're saying you're trying to run the Applet as part of your server-side code. The other interpretation is that you are simply accessing the Applet through the browser that happens to be on the machine being used as the server.
Like I say, post the code that shows how you're trying to use the Applet "on the server". -
Firefox will not open my html files
In the finder, when I double click on an html file, it should open up the file in Firefox.
On my new macbook pro, after using the migration assistant, this feature did not transfer properly. I know how the "open with" system works on get info. When I change html to open with Safari, it works fine. When I change it back to Firefox, no luck.
When I double click on an html file, it opens Firefox, but the page does not load.
Other troubleshooting I have done:
Download and reinstall the latest version of Firefox
Repair permissions
Delete the old Firefox profile, and start a completely new one
Restarted several time
Done all the Apple software updates
Any other suggestions for me?
markMaybe this is something where either have to rebuild launch services; or there are programs or links that seem to default on their own to only use Safari (hard coded, they assume it will always be there, and will always work).
I wonder if there is an add-on system preference where you could go back to the old Internet control panel (I know someone tried to do that but gave up after it got harder with each new OS) where defaults for all file types and applications use to reside, email, ftp, http, gopher, and throw in .docx and everything but kitchen sink, maybe!) -
How to show applets in a html file ?
Hi all
I have created an applet with jdev ,and I also generated the corresponding html file and a main method. So the java file runs standalone when I click on the run button , but when I copied the class file and the html file in a web server, then there is nothing in the applet region ! Can anyone help me ?
Here are the code :
Code of the java file :
// Copyright (c) 2001
package pack_applet;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
* Applet
* <P>
* @author xxxx
public class Capplet extends JApplet {
boolean isStandalone = false;
String x;
String y;
JLabel label = new JLabel();
* Constructs a new instance.
* getParameter
* @param key
* @param def
* @return java.lang.String
public String getParameter(String key, String def) {
if (isStandalone) {
return System.getProperty(key, def);
if (getParameter(key) != null) {
return getParameter(key);
return def;
public Capplet() {
* Initializes the state of this instance.
* init
public void init() {
x = this.getParameter("x", "0");
y = this.getParameter("y", "1");
try {
jbInit();
catch (Exception e) {
e.printStackTrace();
private void jbInit() throws Exception {
this.setSize(new Dimension(400, 400));
this.getContentPane().add(label, BorderLayout.CENTER);
label.setText("x = "+x+" y = "+y);
* start
public void start() {
* stop
public void stop() {
* destroy
public void destroy() {
* getAppletInfo
* @return java.lang.String
public String getAppletInfo() {
return "Applet Information";
* getParameterInfo
* @return java.lang.String[][]
public String[][] getParameterInfo() {
String[][] pinfo =
{"x", "String", ""},
{"y", "String", ""},
return pinfo;
* main
* @param args
public static void main(String[] args) {
Capplet applet = new Capplet();
applet.isStandalone = true;
JFrame frame = new JFrame();
frame.setTitle("Applet Frame");
frame.getContentPane().add(applet, BorderLayout.CENTER);
applet.init();
applet.start();
frame.setSize(400, 420);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } });
static {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
catch(Exception e) {
e.printStackTrace();
And code of the html file :
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<HTML>
<TITLE>
HTML Applet Test Page
</TITLE>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript"><!--
var info = navigator.userAgent; var ns = false;
var ie = (info.indexOf("MSIE") > 0 && _info.indexOf("Win") > 0
&& _info.indexOf("Windows 3.1") < 0)
//--></SCRIPT>
<COMMENT><SCRIPT LANGUAGE="JavaScript1.1"><!--
var _ns = (navigator.appName.indexOf("Netscape") >=0
&& ((_info.indexOf("Win") > 0 && _info.indexOf("Win16") < 0
&& java.lang.System.getProperty("os.version").indexOf("3.5") < 0)
|| (_info.indexOf("Sun") > 0) || (_info.indexOf("Linux") > 0)));
//--></SCRIPT></COMMENT>
pack_applet.Capplet will appear below in a Java enabled browser.<BR>
<SCRIPT LANGUAGE="JavaScript"><!--
if (_ie == true) document.writeln('<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH = 400 HEIGHT = 400 ALIGN = middle NAME = "TestApplet" codebase="HTTP://java.sun.com/products/plugin/1.2/jinstall-12-win32.cab#Version=1,2,0,0"> <NOEMBED><XMP>');
else if(_ns == true) document.writeln('<EMBED type="application/x-java-applet;version=1.2" WIDTH = 400 HEIGHT = 400 ALIGN = middle NAME = "TestApplet" java_CODE = "pack_applet.Capplet" java_CODEBASE = "Capplet.class" "x" = "0" "y" = "1" pluginspage="http://java.sun.com/products/plugin/1.2/plugin-install.html"> <NOEMBED><XMP>');
//--></SCRIPT>
<APPLET CODE = "pack_applet.Capplet" CODEBASE = "Capplet.class" WIDTH = 400 HEIGHT = 400 ALIGN = middle NAME = "TestApplet" >
</XMP>
<PARAM NAME = CODE VALUE = "pack_applet.Capplet" >
<PARAM NAME = CODEBASE VALUE = "Capplet.class" >
<PARAM NAME = NAME VALUE = "TestApplet" >
<PARAM NAME = "type" VALUE = "application/x-java-applet;version=1.2">
<PARAM NAME = "x" VALUE = "0">
<PARAM NAME = "y" VALUE = "1">
</APPLET>
</NOEMBED></EMBED></OBJECT>
</BODY>
</HTML>
Thank you very much.you can load your pdf into your browser using
navigateToURL(new URLRequest("yourpdf.pdf")); -
Help needed:Printing HTML file using javax.print
Hi
I am using the following code which i got form the forum for rpinting an HTML file.
The folllowing code is working fine, but the problem is the content of HTML file is not getting printed. I am geeting a blank page with no content. What is the change that is required in the code? ALso is there any simpler way to implement this. Help needed ASAP.
public boolean printHTMLFile(String filename) {
try {
JEditorPane editorPane = new JEditorPane();
editorPane.setEditorKit(new HTMLEditorKit());
//editorPane.setContentType("text/html");
editorPane.setSize(500,500);
String text = getFileContents(filename);
if (text != null) {
editorPane.setText(text);
} else {
return false;
printEditorPane(editorPane);
return true;
} catch (Exception tce) {
tce.printStackTrace();
return false;
public String getFileContents(String filename) {
try {
File file = new File(filename);
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
StringBuffer sb = new StringBuffer();
while ((line = br.readLine()) != null) {
sb.append(line);
br.close();
return sb.toString();
} catch (Exception tce) {
tce.printStackTrace();
return null;
public void printEditorPane(JEditorPane editorPane) {
try {
HTMLPrinter htmlPrinter = new HTMLPrinter();
htmlPrinter.printJEditorPane(editorPane, htmlPrinter.showPrintDialog());
} catch (Exception tce) {
tce.printStackTrace();
* Sets up to easily print HTML documents. It is not necessary to call any of the setter
* methods as they all have default values, they are provided should you wish to change
* any of the default values.
public class HTMLPrinter {
public int DEFAULT_DPI = 72;
public float DEFAULT_PAGE_WIDTH_INCH = 8.5f;
public float DEFAULT_PAGE_HEIGHT_INCH = 11f;
int x = 100;
int y = 80;
GraphicsConfiguration gc;
PrintService[] services;
PrintService defaultService;
DocFlavor flavor;
PrintRequestAttributeSet attributes;
Vector pjlListeners = new Vector();
Vector pjalListeners = new Vector();
Vector psalListeners = new Vector();
public HTMLPrinter() {
gc = null;
attributes = new HashPrintRequestAttributeSet();
flavor = null;
defaultService = PrintServiceLookup.lookupDefaultPrintService();
services = PrintServiceLookup.lookupPrintServices(flavor, attributes);
// do something with the supported docflavors
DocFlavor[] df = defaultService.getSupportedDocFlavors();
for (int i = 0; i < df.length; i++)
System.out.println(df.getMimeType() + " " + df[i].getRepresentationClassName());
// if there is a default service, but no other services
if (defaultService != null && (services == null || services.length == 0)) {
services = new PrintService[1];
services[0] = defaultService;
* Set the GraphicsConfiguration to display the print dialog on.
* @param gc a GraphicsConfiguration object
public void setGraphicsConfiguration(GraphicsConfiguration gc) {
this.gc = gc;
public void setServices(PrintService[] services) {
this.services = services;
public void setDefaultService(PrintService service) {
this.defaultService = service;
public void setDocFlavor(DocFlavor flavor) {
this.flavor = flavor;
public void setPrintRequestAttributes(PrintRequestAttributeSet attributes) {
this.attributes = attributes;
public void setPrintDialogLocation(int x, int y) {
this.x = x;
this.y = y;
public void addPrintJobListener(PrintJobListener pjl) {
pjlListeners.addElement(pjl);
public void removePrintJobListener(PrintJobListener pjl) {
pjlListeners.removeElement(pjl);
public void addPrintServiceAttributeListener(PrintServiceAttributeListener psal) {
psalListeners.addElement(psal);
public void removePrintServiceAttributeListener(PrintServiceAttributeListener psal) {
psalListeners.removeElement(psal);
public boolean printJEditorPane(JEditorPane jep, PrintService ps) {
if (ps == null || jep == null) {
System.out.println("printJEditorPane: jep or ps is NULL, aborting...");
return false;
// get the root view of the preview pane
View rv = jep.getUI().getRootView(jep);
// get the size of the view (hopefully the total size of the page to be printed
int x = (int) rv.getPreferredSpan(View.X_AXIS);
int y = (int) rv.getPreferredSpan(View.Y_AXIS);
// find out if the print has been set to colour mode
DocPrintJob dpj = ps.createPrintJob();
PrintJobAttributeSet pjas = dpj.getAttributes();
// get the DPI and printable area of the page. use default values if not available
// use this to get the maximum number of pixels on the vertical axis
PrinterResolution pr = (PrinterResolution) pjas.get(PrinterResolution.class);
int dpi;
float pageX, pageY;
if (pr != null)
dpi = pr.getFeedResolution(PrinterResolution.DPI);
else
dpi = DEFAULT_DPI;
MediaPrintableArea mpa = (MediaPrintableArea) pjas.get(MediaPrintableArea.class);
if (mpa != null) {
pageX = mpa.getX(MediaPrintableArea.INCH);
pageY = mpa.getX(MediaPrintableArea.INCH);
} else {
pageX = DEFAULT_PAGE_WIDTH_INCH;
pageY = DEFAULT_PAGE_HEIGHT_INCH;
int pixelsPerPageY = (int) (dpi * pageY);
int pixelsPerPageX = (int) (dpi * pageX);
int minY = Math.max(pixelsPerPageY, y);
// make colour true if the user has selected colour, and the PrintService can support colour
boolean colour = pjas.containsValue(Chromaticity.COLOR);
colour = colour & (ps.getAttribute(ColorSupported.class) == ColorSupported.SUPPORTED);
// create a BufferedImage to draw on
int imgMode;
if (colour)
imgMode = BufferedImage.TYPE_3BYTE_BGR;
else
imgMode = BufferedImage.TYPE_BYTE_GRAY;
BufferedImage img = new BufferedImage(pixelsPerPageX, minY, imgMode);
Graphics myGraphics = img.getGraphics();
myGraphics.setClip(0, 0, pixelsPerPageX, minY);
myGraphics.setColor(Color.WHITE);
myGraphics.fillRect(0, 0, pixelsPerPageX, minY);
java.awt.Rectangle rectangle=new java.awt.Rectangle(0,0,pixelsPerPageX, minY);
// call rootView.paint( myGraphics, rect ) to paint the whole image on myGraphics
rv.paint(myGraphics, rectangle);
try {
// write the image as a JPEG to the ByteArray so it can be printed
Iterator writers = ImageIO.getImageWritersByFormatName("jpeg");
ImageWriter writer = (ImageWriter) writers.next();
// mod: Added the iwparam to create the highest quality image possible
ImageWriteParam iwparam = writer.getDefaultWriteParam();
iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT) ;
iwparam.setCompressionQuality(1.0f); // highest quality
ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageOutputStream ios = ImageIO.createImageOutputStream(out);
writer.setOutput(ios);
// get the number of pages we need to print this image
int imageHeight = img.getHeight();
int numberOfPages = (int) Math.ceil(minY / (double) pixelsPerPageY);
// print each page
for (int i = 0; i < numberOfPages; i++) {
int startY = i * pixelsPerPageY;
// get a subimage which is exactly the size of one page
BufferedImage subImg = img.getSubimage(0, startY, pixelsPerPageX, Math.min(y - startY, pixelsPerPageY));
// mod: different .write() method to use the iwparam parameter with highest quality compression
writer.write(null, new IIOImage(subImg, null, null), iwparam);
SimpleDoc sd = new SimpleDoc(out.toByteArray(), DocFlavor.BYTE_ARRAY.JPEG, null);
printDocument(sd, ps);
// reset the ByteArray so we can start the next page
out.reset();
} catch (PrintException e) {
System.out.println("Error printing document.");
e.printStackTrace();
return false;
} catch (IOException e) {
System.out.println("Error creating ImageOutputStream or writing to it.");
e.printStackTrace();
return false;
// uncomment this code and comment out the 'try-catch' block above
// to print to a JFrame instead of to the printer
/* JFrame jf = new JFrame();
PaintableJPanel jp = new PaintableJPanel();
jp.setImage( img );
JScrollPane jsp = new JScrollPane( jp );
jf.getContentPane().add( jsp );
Insets i = jf.getInsets();
jf.setBounds( 0, 0, newX, y );
jf.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
jf.setVisible( true );*/
return true;
* Print the document to the specified PrintService.
* This method cannot tell if the printing was successful. You must register
* a PrintJobListener
* @return false if no PrintService is selected in the dialog, true otherwise
public boolean printDocument(Doc doc, PrintService ps) throws PrintException {
if (ps == null)
return false;
addAllPrintServiceAttributeListeners(ps);
DocPrintJob dpj = ps.createPrintJob();
addAllPrintJobListeners(dpj);
dpj.print(doc, attributes);
return true;
public PrintService showPrintDialog() {
return ServiceUI.printDialog(gc, x, y, services, defaultService, flavor, attributes);
private void addAllPrintServiceAttributeListeners(PrintService ps) {
// add all listeners that are currently added to this object
for (int i = 0; i < psalListeners.size(); i++) {
PrintServiceAttributeListener p = (PrintServiceAttributeListener) psalListeners.get(i);
ps.addPrintServiceAttributeListener(p);
private void addAllPrintJobListeners(DocPrintJob dpj) {
// add all listeners that are currently added to this object
for (int i = 0; i < pjlListeners.size(); i++) {
PrintJobListener p = (PrintJobListener) pjlListeners.get(i);
dpj.addPrintJobListener(p);
// uncomment this also to print to a JFrame instead of a printer
/* protected class PaintableJPanel extends JPanel {
Image img;
protected PaintableJPanel() {
super();
public void setImage( Image i ) {
img = i;
public void paint( Graphics g ) {
g.drawImage( img, 0, 0, this );
Thanks
RamRam,
I have had printing problems too a year and a half ago. I used all printing apis of java and I still find that it is something java lacks. Now basically you can try autosense. To check whether your printer is capable of printing the docflavor use this PrintServiceLookup.lookupPrintServices(flavor, aset); . If it lists the printer then he can print the document otherwise he can't. I guess that is why you get the error.
Regards,
Kevin -
Reg: Html file download from server
My requirement is download file from server. Am using jsp and servlet this. While downloading the file a dialog box with open, save and cancel option. When try to open html file it, open in the same window .
Req: it should be open in seperate window (ie)
Please advise me how to open a html file in seperate explorer
Am using below Code for download a file:
private void downloadFile( HttpServletResponse response, String strFileType, File file ) throws Exception
logger.trace(Util_Client.INFO, Util_Client.getInfo(), "File download Started.");
BufferedInputStream bufferedInputStream = null;
try {
String strContentType = fileExtnContentTypeMapping.get(strFileType);
if(strContentType == null)
strContentType = fileExtnContentTypeMapping.get(CLConstants.FILE_EXTN_OTHERS);
response.setContentType(strContentType);
String strHeader = "Attachment;Filename=" + file.getName();
response.setHeader("Content-Disposition", strHeader);
byte data[] = new byte[CLConstants.FILE_DOWNLOAD_STREAM_READ_BUFFER];
bufferedInputStream = new BufferedInputStream( new FileInputStream( file ), CLConstants.FILE_DOWNLOAD_STREAM_READ_BUFFER );
int count;
while((count = bufferedInputStream.read(data, 0, CLConstants.FILE_DOWNLOAD_STREAM_READ_BUFFER)) != -1 ) {
response.getOutputStream().write( data, 0, count );
response.getOutputStream().close();
}catch (ClientAbortException clientAbortException) {
clientAbortException.printStackTrace();
}finally{
try {
if( bufferedInputStream != null )
bufferedInputStream.close();
} catch (Exception exceptionFinally) {
exceptionFinally.printStackTrace();
logger.trace(Util_Client.INFO, Util_Client.getInfo(), "File download Ends.");
Thanks in advance
Edited by: sunRP on Oct 11, 2009 9:47 AMThe best you can do is set the correct content type.
Once the file reaches the client's browser it's up to the client and their browser settings to decide what to do with it.
You can't control the client's browser from your servlet. -
CS4 .html files made from .dwt lose all formatting in broswer
Hello all,
I've been working to customize a template I found online, then create a site based on that template. I've got the template visually worked to where I want it. However, any page that I create using the .dwt file is broken (loses all formatting) when viewed in a browser (Firefox or IE).
I can't figure out where I've gone wrong. When it happened the first time I figured I mucked up the template code when I was customizing (very little customizing, really just changing menu item names and adding a contact form). I started over from the beginning and it is happening again. All suggestions are appreciated. Screenshots of the the problem follow. First is the .html file created from my template in design view in CS4. Second is the page viewed in IE, all formatting lost.
MattSome attachments never see the light of day if you use the attachment method. You really need to use the small camera icon in the top toolbar.
However, in this case, seeing a picture isn't going to work, people need to see the live page to try and troubleshoot your problem otherwise it's all a guessing game :-)
Just a guess here, if you are seeing the page correctly in Dreamweaver, and the formatting seems to disappear when you upload the page, then I can only 'guess' that possibly the stylesheet isn't linked correctly,. or the stylesheet hasn't been uploaded, or something in the page or the stylesheeet is throwing your page out.
Nadia
Adobe® Community Expert : Dreamweaver
http://www.perrelink.com.au
Unique CSS Templates |Tutorials |SEO Articles
http://www.DreamweaverResources.com
http://csstemplates.com.au/
http://twitter.com/nadiap -
How to get source of remote html file.
i want to read the remote html file source
i don't have any physical / original path of the file
i have only the url path
example url : http://mydomain.com/myhomepage.html
using this url can i get the source of the file myhomepage.html
thanx
senthil.U can use java.io.*, java.net.* API
here goes a sample code
import java.io.*;
import java.net.*;
public class URLconnecting{
public static void main(String[] args)throws Exception{
URL url = new URL("http://www.yahoo.com");
URLConnection conn = url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while( (line= reader.readLine()) != null) System.out.println(line);
reader.close(); -
Converting html file into zip file and send email attaching zip file
Hi Experts,
I am trying to send email with attachment(html). Which contains more than 7MB. So, It is throwing an error like Size exceeded.
So, Now i need to compress the data for less than 7MB.
I decided to convert HTML File into ZIP File.
Kindly suggest me to convert the HTML file into ZIP file and sending email with attached ZIP file.
Correct answer rewarded,
Thanks & Regards,
N. HARISH KUMARHi Experts,
*// HTML_TAB converting into ZIP File
DATA : zip_tool TYPE REF TO cl_abap_zip,
filename TYPE string ,
filename_zip TYPE string .
DATA : t_data_tab TYPE TABLE OF x255,
bin_size TYPE i,
buffer_x TYPE xstring,
buffer_zip TYPE xstring.
filename = text-007. "'HTML_TAB
*describe the attachment
DESCRIBE TABLE html_tab LINES tab_lines.
bin_size = tab_lines * 255.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = bin_size
IMPORTING
buffer = buffer_x
TABLES
binary_tab = html_tab.
IF sy-subrc <> 0.
* message id sy-msgid type sy-msgty number sy-msgno
* with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*create zip tool
CREATE OBJECT zip_tool.
*add binary file
CALL METHOD zip_tool->add
EXPORTING
name = 'FSSAI_MAIL.HTML'
content = buffer_x.
*get binary ZIP file
CALL METHOD zip_tool->save
RECEIVING
zip = buffer_zip.
CLEAR: t_data_tab[],bin_size.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = buffer_zip
IMPORTING
output_length = bin_size
TABLES
binary_tab = html_tab.
Thanks & Regards,
N. HARISH KUMAR -
Generating an HTML file.....
I would like to generate an HTML file from my javaBean but I am unsure how to do this? Do I just use the PrintWriter methods in java.io and rename the text file to a .html file?
Thanks,
SteveI assume you really mean you want to write a java servlet - in that case read Java Servlet Programming by Jason Hunter. Then you can write html like this:
/**Process the HTTP Post request*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Connection conn = null;
Statement stmt=null;
String query = null;
ResultSet rset = null;
response.setContentType(CONTENT_TYPE);
// nothing will come out on page unless an error occurs
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>AddItemServlet</title></head>");
out.println("<body>");
etc etc. -
How to use an HTML file with Parameters to make an audioClip
HI guys,
I am still working on getting simple sound to work in my program! I have learned that I can use Java.Applet's soundClip object, even when not using an Applet, but I do not know how to work with the URL object. Here is a SCCE so you can see where I am at!
The Java Class:
public class PlaySound {
public static void main(String[ ] args)
throws java.net.MalformedURLException
java.applet.AudioClip clip = java.applet.Applet.newAudioClip(new java.net.URL(null));
clip.play( );
}The HTML file (Lets call it "file.html"):
<html>
<body>
<param name="test" value="test.wav" />
</body>
</html>Now obviously I should not be passing the URL null, what should I pass it and how? Also, is the HTML file written properly? Thanks!
-Christian S.
Edited by: Christ_Guard on Jun 10, 2008 9:41 AMChrist_Guard wrote:
Thanks! Thats exactly what I needed! Should I be saving my sound files in the bin Directory?That was just the simplest solution. Resources can be anywhere, as long as you know where! This icon tutorial gives some examples.
[http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html#getresource] -
Hello,
I have a question about parsing HTML files. Usually when I get an HTML file and I need to find all the text in it I do this. This stuff just collects all of the hyperlinks and ignores all the html tags just keeping the actual text. It's fine for smaller files but occasionally I'll hit a large online text file and it will work but its way to slow for large files. I don't need to do all of this HTML tag stripping however for text files. Is there a way to still grab all the text without doing any tag searching to make it faster?
thanks,
private void find() throws IOException
//Really slow for large text files. Need a way to just use a regular scanner on an internet text file
new ParserDelegator().parse(new InputStreamReader(myBase.openStream()),
new ParserListener(),
true);
* Inner class for processing all "<a href.."> tags when reading a base URL.
private class ParserListener extends HTMLEditorKit.ParserCallback
final String IGNORED_LINKS = "^(http|mailto|\\W).*";
public void handleStartTag (HTML.Tag t, MutableAttributeSet a, int pos)
if (t == HTML.Tag.A)
String href = (String)(a.getAttribute(HTML.Attribute.HREF));
//System.out.println(href);
//System.out.println(href.matches(IGNORED_LINKS) + "\t" + href);
if (! (href == null || href.matches(IGNORED_LINKS)) && !myURLs.contains(href))
myURLs.add(href);
//TODO fix
if (t == HTML.Tag.TITLE)
String title = (String) (a.getAttribute(HTML.Attribute.TITLE));
if (!(title == null))
myTitle = title;
else myTitle = "No title was found";
public void handleText (char[] data, int pos)
myText.append(" ");
myText.append(data);
}JFactor2004 wrote:
My question is. If I know an html file is actually just a txt fileThis isn't a question. HTML files are text by definition.
is it possible to look through it (maybe use something similar to a regular scanner) without doing anything with html.That depends on what you mean by "doing something with HTML". You can certainly read it one line at a time.
Maybe you are looking for
-
Windows error: iTunes crashes (uninstall and reinstall does not work)
Hello all. I (and another user) have had a problem with iTunes crashing when trying to open it. Windows just generates the typical vague error message that explains nothing as to what the problem is. Uninstalling and reinstalling did not work, and us
-
HP Officejet Pro 8500 A910 Scan to email failure Error Server Failure Try again Later message
HP Officejet Pro 8500 A910n ( CM758A ) Scan to email failure Error Server Failure Try again Later message Ran HP Print & Scan Doctor - finds no problems. When sending a scanned document to the user email it has " Error Server Failure Try again L
-
Changing charset from UTF-8 to iso-8859-1
Hi, I am deploying my web service in Weblogic Server 9.2.2. The result is returned using encoding "UTF-8". How can I alter this so that the result wil be returned using encoding "iso-8859-1"? Could some one help please? Thanks in advacne Mike
-
I need activation code for my ipad
PLeas i need activation code for my ipad becouse i cant open it ana i know the apple id and password
-
Is there a script to delete frames?
Hi is there a script to delete frames on photos? often i have to delete black or white frames or others colors , i 'm looking for a script to do it thanks cheers