Java problem

Discussion in 'OT Technology' started by fatlip, Feb 6, 2003.

  1. fatlip

    fatlip Transcendence Into The Peripheral

    Joined:
    Jun 16, 2001
    Messages:
    522
    Likes Received:
    0
    Location:
    UK
    Hi guys, i've asked this at several other forums, but so far no one has the answer. I've created an e-commerce application using servlets, now I'm trying to build a simple browser to view these servlets. I've made a very simple one that works for the most part, except when comes to buttons (submit type inputs) within the html, like the one below:

    Code:
    out.println("<TD><FORM ACTION=\"" +Orders+ "\">\n" +
    "<INPUT TYPE=\"HIDDEN\" NAME=\"ItemId\"VALUE=\"" +temp.getItemId( + "\">\n" +
    "<P>\n<CENTER>\n" +
    "<INPUT TYPE=\"SUBMIT\" NAME=\"Operation\"VALUE=\"Delete\">\n" +
    "</CENTER>\n<P>\n</FORM></TD></TR>");
    clicking on the button simply does nothing, what do I have to do to make the browser use these buttons correctly. Here's the code for my browser so far:

    Code:
    package project;
    
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import javax.swing.*;
    import javax.swing.event.*;
    
    public class Browser extends JFrame
    {
    	public JEditorPane viewer;
    	public JButton browse, search, view, checkout;
    
    	public Browser()
    	{	//create the components that make up the browser
    		super("Project Browser");
    		browse = new JButton("Browse stock");
    		search = new JButton("Search");
    		view = new JButton("View basket");
    		checkout = new JButton("Proceed to checkout");
    		JToolBar bar = new JToolBar();
    		bar.add(browse);
    		bar.add(search);
    		bar.add(view);
    		bar.add(checkout);
    		viewer = new JEditorPane();
    		viewer.setEditable(false);
    
    		//get a container and place the components on it
    		Container c = getContentPane();
    		c.setLayout(new BorderLayout());
    		c.add(bar, BorderLayout.NORTH);
    		c.add(new JScrollPane(viewer), BorderLayout.CENTER);
    
    		viewer.addHyperlinkListener(new LinkListener(  ));
    		setSize(800, 600);
    		setVisible(true);
    		String s = "http://localhost:8080/tomcat-docs/Selector.html";
    	    open(s);
    	}
    
      	public void open(String url)
      	{
        	try	{
          		URL page = new URL(url);
          		viewer.setPage(page);
        	}
        	catch (Exception e) {
          		System.out.println("Couldn't open " +url+ ":" + e);
        	}
      	}
    
      	class LinkListener implements HyperlinkListener
      	{	public void hyperlinkUpdate(HyperlinkEvent he)
      		{	HyperlinkEvent.EventType type = he.getEventType(  );
    	      	if (type == HyperlinkEvent.EventType.ENTERED)
    	        	viewer.setCursor(
    	            Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    	      	else if (type == HyperlinkEvent.EventType.EXITED)
    	        	viewer.setCursor(Cursor.getDefaultCursor(  ));
    	      	else if (type == HyperlinkEvent.EventType.ACTIVATED)
    	        	open(he.getURL().toExternalForm(  ));
    	    }
    	}
    
    
    	public static void main(String[] args)
    	{
    	    new Browser();
    
      	}
    }
     
  2. crotchfruit

    crotchfruit Guest

    i see two errors so far:

    1) you don't close the "temp.getItemId(" function.. how does your code even compile?!?!

    2) in two places you have no space between a \" and a VALUE.

    regardless, i see no reason why the button wouldn't try to go to the "form action". i cut pasted the html into a simple webpage and it worked fine.
     

Share This Page