Cookies, JavaScript and Java-Servlets

I'd like to know if there is a possibility to connect Java-Servlets and JavaScript. I want to place a cookie on my system when calling the Java Servlet. This is just working fine. My problem is that I don't know how to read this cookie with JavaScript. Is there a detailed homepage, where I can find a solution to my problem?
Best regards,
Henriette

A good place for Javascript is Webmonkey.com.
Good Luck,
J.Clancey

Similar Messages

  • Problem with JSP and Java Servlet Web Application....

    Hi every body....
    I av developed a web based application with java (jsp and Java Servlets)....
    that was working fine on Lane and Local Host....
    But when i upload on internet with unix package my servlets and Java Beans are not working .....
    also not access database which i developed on My Sql....
    M using cpanel support on web server
    Plz gave me solution...
    Thanx looking forward Adnan

    You need to elaborate "not working" in developer's perspective instead of in user's perspective.

  • COMMUNICATION BETWEEN JAVASCRIPT AND JAVA APPLET: US$20 AWARD FOR SOLUTION!

    COMMUNICATION BETWEEN JAVASCRIPT AND JAVA APPLET PROBLEM (Easy Filter Java Applet) -
    US$20 TO ANYONE WHO CAN RESOLVE THE PROBLEM
    To forum visitors:
    I am prepared to pay a standard shareware fee of US$20 to a user who can resolve this technical problem.
    If your advice resolves the problem, I'll forward the payment to your postal address (include your
    address with your reply, and also your email address)
    I am attempting to enable a HTML button (using Javascript's onClick command) to directly input a number into one of the parameter text boxes in the Easy Filter Java applet (ie, enter a new color value number in the text field of the standard Colors Multiplicator Filter interface).
    The applet is Freeware and can be downloaded at: http://www.javazoom.net/applets/easyfilter10/EasyFilter10.html
    (It is a very effective bitmap display and editing utility)
    To achieve this, I am trying to access the part of the applet that defines and sets the textbox. The text box is defined in the .class file by accessing the parameter details in the genericfilter.txt file (accompanies the .class files). I need to access 'private String appletInitialize()' and then one of the 'textFieldParameters' which sets the textbox.
    I understand the basic syntax for referencing the applet:
    document.appletname.setString("An example"). However, accessing the text fields in this applet is more complex!!
    Please can you recommend the correct Javascript syntax to achieve communication with the applet.
    Thank you for your kind assistance.
    JM Graham
    [email protected]
    The Java source code for the applet: EasyFilter.class
    # Easy Filter - E.B/JavaZOOM 1999 #
    # Contact: [email protected] #
    # http://javazoom.hypermart.net #
    /* Originally compiled from EasyFilter.java */
    import java.awt.*;
    import java.io.*;
    import java.net.*;
    import java.applet.Applet;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.image.MemoryImageSource;
    import java.awt.image.PixelGrabber;
    import java.util.Vector;
    public synchronized class EasyFilter extends Applet implements KeyListener
    private String paramFileName;
    private Color bgColor;
    private Color fgColor;
    private Color parColor;
    private Color sepColor;
    private Color titleColor;
    private Color helpColor;
    private int WinWidth;
    private int WinHeight;
    private String title;
    private String logoFileName;
    private String originalImageFileName;
    private String filteredCaption;
    private String originalCaption;
    private Vector paramsName;
    private Vector paramsValue;
    private Vector paramsComment;
    private Panel panelParameters[];
    private Label labelParameters[];
    private TextField textFieldParameters[];
    private Label labelComments[];
    private int nbParameters;
    private ScrollPane scrollPaneParams;
    private Panel panelParams;
    private Image theLogo;
    private Image theOriginalImage;
    private Image theFilteredImage;
    private int theOriginalPixelArray[];
    private int logoWidth;
    private int logoHeight;
    private int imageWidth;
    private int imageHeight;
    private drawCanvas canvasTitle;
    private Panel panelTitle;
    private Label labelTitle;
    private Panel panelImages;
    private Panel panelOriginalImage;
    private drawCanvas canvasOriginalImage;
    private Label labelOriginalImage;
    private Panel panelFilteredImage;
    private drawCanvas canvasFilteredImage;
    private Label labelFilteredImage;
    private Panel panelHelp;
    private Label labelHelp;
    private int Yspc;
    private FilterImplementation theFilter;
    public void init()
    String string = null;
    string = appletInitialize();
    setBackground(bgColor);
    if (string != null)
    removeAll();
    setBackground(Color.white);
    setForeground(Color.black);
    Label label = new Label(new StringBuffer("Error: ").append(string).toString(), 1);
    Panel panel = new Panel();
    panel.add(label);
    add(panel);
    setLayout(new FlowLayout(1, 5, Yspc));
    public void keyPressed(KeyEvent keyEvent)
    panelHelp.removeAll();
    boolean flag = true;
    if (KeyEvent.getKeyText(keyEvent.getKeyCode()).equals("Enter"))
    for (int i = 0; i < nbParameters; )
    try
    paramsValue.setElementAt(new Double(textFieldParameters.getText()), i);
    i++;
    catch (NumberFormatException e)
    labelHelp.setText(labelParameters[i].getText() + ": Not a Number");
    flag = false;
    break;
    if (flag == 1)
    labelHelp.setText(" .... Running, please wait .... ");
    labelHelp.setAlignment(1);
    panelHelp.add(labelHelp);
    panelHelp.doLayout();
    theFilter.updateParameters(paramsValue);
    theFilter.computeFilter();
    theFilteredImage = createImage(new MemoryImageSource(theFilter.getFinalImageWidth(), theFilter.getFinalImageHeight(), theFilter.getFinalImageBuffer(), 0, theFilter.getFinalImageWidth()));
    canvasFilteredImage.setImage(theFilteredImage);
    canvasFilteredImage.setBounds(0, 0, theFilter.getFinalImageWidth(), theFilter.getFinalImageHeight());
    canvasFilteredImage.repaint();
    panelHelp.removeAll();
    labelHelp.setText("- Done -");
    else
    labelHelp.setText("- Press Enter to run the Filter -");
    labelHelp.setAlignment(1);
    panelHelp.add(labelHelp);
    panelHelp.doLayout();
    public void keyReleased(KeyEvent keyEvent)
    public void keyTyped(KeyEvent keyEvent)
    private String appletInitialize()
    WinWidth = size().width;
    WinHeight = size().height;
    if (getParameter("bgcolor") == null)
    bgColor = new Color(0, 0, 40);
    else
    bgColor = new Color(Integer.parseInt(getParameter("bgcolor"), 16));
    if (getParameter("fgcolor") == null)
    fgColor = new Color(255, 255, 255);
    else
    fgColor = new Color(Integer.parseInt(getParameter("fgcolor"), 16));
    if (getParameter("sepcolor") == null)
    sepColor = new Color(158, 128, 128);
    else
    sepColor = new Color(Integer.parseInt(getParameter("sepcolor"), 16));
    if (getParameter("parcolor") == null)
    parColor = new Color(24, 24, 24);
    else
    parColor = new Color(Integer.parseInt(getParameter("parcolor"), 16));
    if (getParameter("titlecolor") == null)
    titleColor = new Color(255, 255, 0);
    else
    titleColor = new Color(Integer.parseInt(getParameter("titlecolor"), 16));
    if (getParameter("helpcolor") == null)
    helpColor = new Color(0, 255, 255);
    else
    helpColor = new Color(Integer.parseInt(getParameter("helpcolor"), 16));
    paramsName = new Vector();
    paramsValue = new Vector();
    paramsComment = new Vector();
    paramFileName = getParameter("paramfile");
    String string = readParams(paramFileName);
    if (string != null)
    return string;
    MediaTracker mediaTracker = new MediaTracker(this);
    theOriginalImage = getImage(getDocumentBase(), originalImageFileName);
    mediaTracker.addImage(theOriginalImage, 0);
    if (logoFileName != null)
    theLogo = getImage(getDocumentBase(), logoFileName);
    mediaTracker.addImage(theLogo, 1);
    try
    mediaTracker.waitForAll();
    catch (InterruptedException e1)
    return "Error while loading image";
    if (mediaTracker.isErrorAny())
    return "Error while loading image";
    if (logoFileName != null)
    logoWidth = theLogo.getWidth(this);
    logoHeight = theLogo.getHeight(this);
    imageWidth = theOriginalImage.getWidth(this);
    imageHeight = theOriginalImage.getHeight(this);
    theOriginalPixelArray = new int[imageWidth * imageHeight];
    PixelGrabber pixelGrabber = new PixelGrabber(theOriginalImage, 0, 0, imageWidth, imageHeight, theOriginalPixelArray, 0, imageWidth);
    try
    pixelGrabber.grabPixels();
    panelTitle = new Panel();
    canvasTitle = new drawCanvas();
    labelTitle = new Label();
    panelTitle.setLayout(new FlowLayout(1, 10, Yspc));
    add(panelTitle);
    panelTitle.setBackground(bgColor);
    panelTitle.add(canvasTitle);
    canvasTitle.setImage(theLogo);
    canvasTitle.setBounds(0, 0, logoWidth, logoHeight);
    labelTitle.setText(title);
    catch (InterruptedException e2)
    return "Internal Error, Try RELOAD !";
    if (title != null)
    panelTitle.add(labelTitle);
    labelTitle.setForeground(titleColor);
    labelTitle.setFont(new Font("Dialog", 1, 14));
    panelImages = new Panel();
    panelOriginalImage = new Panel();
    canvasOriginalImage = new drawCanvas();
    labelOriginalImage = new Label();
    panelFilteredImage = new Panel();
    canvasFilteredImage = new drawCanvas();
    labelFilteredImage = new Label();
    panelImages.setLayout(new FlowLayout(1, 10, Yspc));
    add(panelImages);
    panelImages.setBackground(bgColor);
    panelOriginalImage.setLayout(new BorderLayout(0, 2));
    panelImages.add(panelOriginalImage);
    panelOriginalImage.setBackground(Color.black);
    panelOriginalImage.add("Center", canvasOriginalImage);
    canvasOriginalImage.setImage(theOriginalImage);
    canvasOriginalImage.setBounds(0, 0, imageWidth, imageHeight);
    labelOriginalImage.setText(originalCaption);
    labelOriginalImage.setAlignment(1);
    panelOriginalImage.add("South", labelOriginalImage);
    labelOriginalImage.setBackground(Color.lightGray);
    labelOriginalImage.setForeground(Color.black);
    labelOriginalImage.setFont(new Font("SansSerif", 0, 10));
    panelFilteredImage.setLayout(new BorderLayout(0, 2));
    panelImages.add(panelFilteredImage);
    panelFilteredImage.setBackground(Color.black);
    panelFilteredImage.add("Center", canvasFilteredImage);
    theFilter = new FilterImplementation(paramsValue, theOriginalPixelArray, imageWidth, imageHeight);
    theFilter.computeFilter();
    theFilteredImage = createImage(new MemoryImageSource(theFilter.getFinalImageWidth(), theFilter.getFinalImageHeight(), theFilter.getFinalImageBuffer(), 0, theFilter.getFinalImageWidth()));
    canvasFilteredImage.setImage(theFilteredImage);
    canvasFilteredImage.setBounds(0, 0, theFilter.getFinalImageWidth(), theFilter.getFinalImageHeight());
    labelFilteredImage.setText(filteredCaption);
    labelFilteredImage.setAlignment(1);
    panelFilteredImage.add("South", labelFilteredImage);
    labelFilteredImage.setBackground(Color.lightGray);
    labelFilteredImage.setFont(new Font("SansSerif", 0, 10));
    scrollPaneParams = new ScrollPane(0);
    panelParams = new Panel();
    nbParameters = paramsName.size();
    int i = WinHeight - (33 + 7 * Yspc + logoHeight + imageHeight + 23);
    if (i < Yspc + 2 + 24)
    i = Yspc + 2 + 24;
    scrollPaneParams.setBounds(0, 0, WinWidth - 10, i);
    panelParams.setLayout(new GridLayout(nbParameters, 1, 5, Yspc / 2));
    scrollPaneParams.add(panelParams);
    panelParams.setBackground(sepColor);
    panelParameters = new Panel[nbParameters];
    labelParameters = new Label[nbParameters];
    textFieldParameters = new TextField[nbParameters];
    labelComments = new Label[nbParameters];
    for (int j = 0; j < nbParameters; j++)
    panelParameters[j] = new Panel();
    panelParameters[j].setLayout(new FlowLayout(0, 5, 1));
    panelParams.add(panelParameters[j]);
    panelParameters[j].setBackground(parColor);
    labelParameters[j] = new Label();
    labelParameters[j].setText((String)paramsName.elementAt(j));
    panelParameters[j].add(labelParameters[j]);
    labelParameters[j].setForeground(fgColor);
    labelParameters[j].setFont(new Font("Dialog", 1, 12));
    textFieldParameters[j] = new TextField(8);
    textFieldParameters[j].setText(paramsValue.elementAt(j).toString());
    panelParameters[j].add(textFieldParameters[j]);
    textFieldParameters[j].setBackground(fgColor);
    textFieldParameters[j].addKeyListener(this);
    labelComments[j] = new Label();
    labelComments[j].setText((String)paramsComment.elementAt(j));
    panelParameters[j].add(labelComments[j]);
    labelComments[j].setForeground(fgColor);
    add(scrollPaneParams);
    panelHelp = new Panel();
    labelHelp = new Label();
    panelHelp.setLayout(new FlowLayout(1, 5, 0));
    add(panelHelp);
    panelHelp.setBackground(bgColor);
    labelHelp.setText(" Change colour values and press enter ");
    labelHelp.setAlignment(1);
    panelHelp.add(labelHelp);
    labelHelp.setForeground(helpColor);
    return null;
    private String readParams(String string1)
    Object object1;
    String string2;
    if (string1 == null)
    return "Filename of filter's parameters needed";
    try
    URL uRL = new URL(getDocumentBase(), string1);
    URLConnection uRLConnection = uRL.openConnection();
    uRLConnection.setDoInput(true);
    uRLConnection.setUseCaches(false);
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(uRLConnection.getInputStream()));
    string2 = null;
    catch ()
    return object1.getMessage();
    catch ()
    return object1.getMessage();
    catch ()
    return object1.getMessage();
    if (bufferedReader != null)
    Object object2;
    try
    for (object2 = bufferedReader.readLine(); object2 != null && string2 == null; object2 = bufferedReader.readLine())
    string2 = extractFormat(object2);
    catch ()
    string2 = object2.getMessage();
    finally
    bufferedReader.close();
    if (string2 != null)
    return string2;
    else
    return null;
    private String extractFormat(String string1)
    if (string1.length() == 0)
    return null;
    int i = 0;
    int j = string1.indexOf(" ", i);
    if (j == -1)
    return "Bad format error (space missing)";
    String string2 = string1.substring(i, j);
    if (string2.equals("TITLE"))
    i = j;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format (Double quote in TITLE missing)";
    i = j + 1;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format (Double quote in TITLE missing)";
    title = string1.substring(i, j);
    return null;
    if (string2.equals("ORIGINALCAPTION"))
    i = j;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format (Double quote in ORIGINALCAPTION missing)";
    i = j + 1;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format (Double quote in ORIGINALCAPTION missing)";
    originalCaption = string1.substring(i, j);
    return null;
    if (string2.equals("FILTEREDCAPTION"))
    i = j;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format (Double quote in FILTEREDCAPTION missing)";
    i = j + 1;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format (Double quote in FILTEREDCAPTION missing)";
    filteredCaption = string1.substring(i, j);
    return null;
    if (string2.equals("LOGO"))
    i = j + 1;
    j = string1.length();
    logoFileName = string1.substring(i, j);
    return null;
    if (string2.equals("ORIGINALIMAGE"))
    i = j + 1;
    j = string1.length();
    originalImageFileName = string1.substring(i, j);
    return null;
    if (!string2.equals("PARAM"))
    return null;
    i = j;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format in a PARAM line";
    i = j + 1;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format in a PARAM line";
    paramsName.addElement(string1.substring(i, j));
    i = j + 2;
    j = string1.indexOf(32, i);
    if (j == -1)
    return "Bad format in a PARAM line";
    try
    paramsValue.addElement(new Double(string1.substring(i, j)));
    j = string1.indexOf(34, i);
    catch (NumberFormatException e)
    return "Bad format in a PARAM line";
    if (j == -1)
    return "Bad format (Double quote in PARAM comment missing)";
    i = j + 1;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format (Double quote in PARAM comment missing)";
    paramsComment.addElement(string1.substring(i, j));
    return null;
    public EasyFilter()
    logoHeight = 33;
    Yspc = 5;

    Addition to my above submission
    To clarify, I'll offer the US$20 to the FIRST person who offers me a workable solution to the problem, not to everyone!!!
    JMGRAHAM

  • Check if client browser supports javascript and java

    Hi everybody,
    I would like to know if there is any means by which we could check on the server side, if the client's browser supports Javascript and java.
    bye
    Praveen

    It would be a bit of a hack, but you could embed a Javascript snippit in the actual HTML that would use document.write() to output a hidden tag. If your server recieved the hidden tag on a GET or POST request, you would know that Javascript was enabled.
    - Saish

  • Unicode, UTF-8 and java servlet woes

    Hi,
    I'm writing a content management system for a website about russian music.
    One problem I'm having is trying to get a java servlet to talk Unicode to the Content mangament client.
    The client makes a request for a band, the server then sends the XML to the client.
    The XML reading works fine and the client displays the unicode fine from an XML file read locally (so the XMLReader class works fine).
    The servlet unmarshals the request perfectly (its just a filename).
    I then find the correct class, and pass it through the XML writer. that returns the XML as string, that I simply put into the output stream.
    out.write(XMLWrite(selectedBand));I have set correct header property
    response.setContentType("text/xml; charset=UTF-8");And to read it I
             //Make our URL
             URL url = new URL(pageURL);
             HttpURLConnection conn = (HttpURLConnection)url.openConnection();
             conn.setRequestMethod("POST");
             conn.setDoOutput(true); // want to send
             conn.setRequestProperty( "Content-type", "application/x-www-form-urlencoded" );
             conn.setRequestProperty( "Content-length", Integer.toString(request.length()));
             conn.setRequestProperty("Content-Language", "en-US"); 
             //Add our paramaters
             OutputStream ost = conn.getOutputStream();
             PrintWriter pw = new PrintWriter(ost);
             pw.print("myRequest=" + URLEncoder.encode(request, "UTF-8")); // here we "send" our body!
             pw.flush();
             pw.close();
             //Get the input stream
             InputStream ois = conn.getInputStream();
                InputStreamReader read = new InputStreamReader(ois);
             //Read
             int i;
             String s="";
             Log.Debug("XMLServerConnection", "Responce follows:");
             while((i = read.read()) != -1 ){
              System.out.print((char)i);
              s += (char)i;
             return s;now when I print
    read.getEncoding()It claims:
    ISO8859_1Somethings wrong there, so if I force it to accept UTF-8:
    InputStreamReader read = new InputStreamReader(ois,"UTF-8");It now claims its
    UTF8However all of the data has lost its unicode, any unicode character is replaced with a question mark character! This happens even when I don't force the input stream to be UTF-8
    More so if I view the page in my browser, it does the same thing.
    I've had a look around and I can't see a solution to this. Have I set something up wrong?
    I've set, "-encoding utf8" as a compiler flag, but I don't think this would affect it.

    I don't know what your problem is but I do have a couple of comments -
    1) In conn.setRequestProperty( "Content-length", Integer.toString(request.length())); the length of your content is not request.length(). It is the length of th URL encoded data.
    2) Why do you need to send URL encoded data? Why not just send the bytes.
    3) If you send bytes then you can write straight to the OutputStream and you won't need to convert to characters to write to PrintWriter.
    4) Since you are reading from the connection you need to setDoInput() to true.
    5) You need to get the character encoding from the response so that you can specify the encoding in           InputStreamReader read = new InputStreamReader(ois, characterEncoding);
    6) Reading a single char at a time from an InputStream is very inefficient.

  • AS3 and Java Servlets

    Hey guys, I was recently able to get AS3.0 to connect to a
    MySQL database using PHP. However, my employer decided that he
    wants me to use a Java Servlet for the communications rather than
    PHP. I have written the servlets and they are all working properly,
    however, I can't get flash to run them properly in the application.
    When running the servlet I get an error stating "Error opening URL"
    Are there any specific changes that I need to change in my code so
    that I am able to communicate with a servlet? I am posting this in
    the hopes there is an easy solution, or if there is a tutorial
    anyone could provide. If need be, I can post my code.
    Thanks!

    I don't know anything about the server code itself, but is it
    still running on the same domain as the swf? Otherwise you would
    need to look at crossdomain.xml permissions.

  • Help with Error on tomcat and java servlet

    i've just recently installed Dialect Payment client onto my server and is using Java to correspond with the server. I can run the diagnostic test run perfectly fine but when I have compiled the form and the app, I keep getting the error:
    javax.servlet.ServletException: Invoker service() exception
         org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:478)
         org.apache.catalina.servlets.InvokerServlet.doPost(InvokerServlet.java:170)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
         filters.ExampleFilter.doFilter(ExampleFilter.java:149)
    root cause
    com.qsipayments.utility.AssertionError: InvalidConfigException can only be thrown on reload
         com.qsipayments.utility.Assert.shouldNotReachHere(Assert.java:246)
         PaymentClient.util.PCConfigurationService.getConfiguration(PCConfigurationService.java:72)
         com.qsipayments.utility.logging.Logging.initialise(Logging.java:198)
         PaymentClient.PaymentClientBase.initialiseLogging(PaymentClientBase.java:1179)
         PaymentClient.PaymentClientBase.<init>(PaymentClientBase.java:106)
         PaymentClient.PaymentClientImpl.<init>(PaymentClientImpl.java:26)
         Java_3DS_3P_AuthPay_DO.doPost(Java_3DS_3P_AuthPay_DO.java:116)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
         org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:420)
         org.apache.catalina.servlets.InvokerServlet.doPost(InvokerServlet.java:170)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
         filters.ExampleFilter.doFilter(ExampleFilter.java:149)
    If anyone can help or advise me on this matter, it would be incredibly fantastic! I've tried asking the people who have provided me with the program but they dont seem to have anything useful that i can do to fix the error. I was told by my server admin that it was in the coding, but they claim that it has nothing to do with the coding.
    PLEASE HELP.I've been working on this for months and about to die from frustration!

    I haven't worked with this vendor product, but here are some ideas you might find useful:
    It appears is a configuration problem when using the vendor software (but they already told you that, didn't they!!!).
    I say the above because these lines in your printout are from vendor supplied objects (that you didn't create):
    com.qsipayments.utility.AssertionError: InvalidConfigException can only be thrown on reload
    com.qsipayments.utility.Assert.shouldNotReachHere(Assert.java:246)
    PaymentClient.util.PCConfigurationService.getConfiguration(PCConfigurationService.java:72)
    I suggest creating a brand new project with the simplist use of the above vendor project and get it to work.
    You can use the vendor's (on line) documentation to do this. Deploy it in production to ensure there are no deployment issues. Work closely with one of
    your fellow employees (more than one pair of eyes can pick up stuff that you miss). Next, look at what features of the vendor software the originial project uses and what features the sample project uses. Try to implement a subset of functionality of the orginial project into the sample project and get that to work. Implement the next feature, test, etc. Do small experiments at a time so you can easily isolate what doesnt work.
    If none of the above works for you, try contacting the manufacturer or thier support web site. If none of the above works, look into using a compeditors product.

  • Need Help Badly on Shopping Cart Using JSP And Java Servlet

    Hi All,
    This is the 1st time i am trying to create a shopping cart using JSP and Servlet.
    I have read through a few acticles but i still do not get the whole idea of how it works.
    Please guide me as i need help very badly.
    Thanks.
    This is one of the jsp page which displays the category of products user would like to buy : Products.jsp
    <html>
    <head>
    <title>Purchase Order</title>
    </head>
    <body topmargin="30">
    <table border="0" width="100%" id="table1" cellpadding="2">
         <tr>
              <td bgcolor="#990000" width="96">
              <p align="center"><b><font face="Verdana" size="2" color="#FFFFFF">
              Code</font></b></td>
              <td bgcolor="#990000" width="260">
              <p align="center"><b><font face="Verdana" size="2" color="#FFFFFF">
              Description </font></b></td>
              <td bgcolor="#990000" width="130">
              <p align="center"><b><font face="Verdana" size="2" color="#FFFFFF">Brand
              </font></b></td>
              <td bgcolor="#990000" width="146">
              <p align="center"><b><font face="Verdana" size="2" color="#FFFFFF">UOM
              </font></b></td>
              <td bgcolor="#990000" width="57">
              <p align="center"><b><font face="Verdana" size="2" color="#FFFFFF">Unit<br>
              Price </font></b></td>
              <td bgcolor="#990000" width="62">
              <p align="center"><b><font face="Verdana" size="2" color="#FFFFFF">
              Carton<br>
              Price </font></b></td>
              <td bgcolor="#990000" width="36">
              <p align="center"><b><font face="Verdana" size="2" color="#FFFFFF">
              Qty</font></b></td>
              <td bgcolor="#990000" width="65">
              <p align="center"><b><font face="Verdana" size="2" color="#FFFFFF">Add<br>
              To Cart</font></b></td>
         </tr>
    <tr>
    <td align="center" width="96" bgcolor="#CCCCCC">
    <font face="Verdana, Arial, Helvetica, sans-serif" size="2">123</font>
    </td>
    <td align="center" width="260" bgcolor="#CCCCCC">
    <font face="Verdana, Arial, Helvetica, sans-serif" size="2">Tom Yam</font>
    </td>
    <td align="center" width="130" bgcolor="#CCCCCC">
    <font face="Verdana, Arial, Helvetica, sans-serif" size="2">Nissin</font>
    </td>
    <td align="center" width="146" bgcolor="#CCCCCC">
    <font face="Verdana, Arial, Helvetica, sans-serif" size="2">12 x 10's</font>
    </td>
    <td align="center" width="57" bgcolor="#CCCCCC">
    <font face="Verdana, Arial, Helvetica, sans-serif" size="2">$3.85</font>
    </td>
    <td align="center" width="62" bgcolor="#CCCCCC">
    <font face="Verdana, Arial, Helvetica, sans-serif" size="2">$46.2</font>
    </td>
    <td align="center" width="36" bgcolor="#CCCCCC">
    <!--webbot bot="Validation" S-Data-Type="Integer" S-Number-Separators="x" -->
    <p align="center"><input type="Integer" name="Q10005" size="1"></p>
    </td>
    <td align="center" width="65" bgcolor="#CCCCCC">
    <p><input type="checkbox" name="checkbox" value="123"></p>
    </tr>
    <tr>
    </table>
    <table border="0" width="100%" id="table2">
         <tr>
              <td>
              <div align="right">          
                   <input type="hidden" name="hAction" value="AddToCart"/> 
              <input type=submit name="submit" value="Add To Cart"/>                     
    </div>
    </td>
         </tr>
    </table>
    </body>
    </html>
    After user has make his selection by entering the qty and ticking on the check box, he would click the "Add To Cart" button ... and this would call my servlet : AddToAddControlSerlvet.java
    import javax.servlet.http.*;
    import javax.servlet.*;
    import java.io.*;
    import java.util.*;
    import java.util.ArrayList;
    public class AddToCartControlServlet extends HttpServlet
         public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException
              String action = req.getParameter("hAction");
              if (action.equals("AddToCart"))
                   addToCart(req,res);
         public void addToCart(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
              try
                   String url = "";
                   String[] addList = req.getParameterValues("checkbox");
                   HttpSession sess = req.getSession(true);
                   //String sessionID = sess.getId();
                   DBClass dbClass = new DBClass();
                   ArrayList cartList = new ArrayList();
                   for (int i = 0; i < addList.length; i++)
                        String productCode = (String)addList;
                        int qty = Integer.parseInt(req.getParameter("Q"+productCode));
                        Products product = dbClass.getProductDetail(productCode);
                        double totalUnitAmt = qty * product.getUnitPrice();
                        double totalCartonAmt = qty * product.getCartonPrice();
                        Order order = new Order(product.getProductCode(),product.getProductDesc(),product.getBrandName(),product.getUom(),qty,product.getUnitPrice(),product.getCartonPrice(),totalUnitAmt,totalCartonAmt);
                        cartList.add(order);
                   sess.setAttribute("cartList", cartList);
                   url = "/Cart/CartDetails.jsp";
                   ServletContext sc = getServletContext();
                   RequestDispatcher rd = sc.getRequestDispatcher(url);
                   rd.forward(req, res);
              catch (Exception e)
                   System.out.println(e);
    From here, i would get the list of items which user has selected and add to the cartList, then i would direct the user to CartDetails.jsp which displayed the items user has selected.
    From there, user would be able to remove or to continue shopping by selecting other category.
    How i do store all the items user has selected ... everytime he would wan to view his cart ...
    As i would be calling from jsp to servlet .. or jsp to servlet ... and i do not know how i should go about in creating the shopping cart.

    Hi !
    Yon can use a data structure as vector and store the items selected by the user into the vector . Keep the vector in session using session object , so the user can access the entire shopping cart from anywhere in the application .
    Then , you can change the cart accordingly .
    Hope this works.
    Cheers ,
    Pranav

  • IE5.5 SP2 and Java servlets

    I have a servlet program that is web based and I need your help. It works fine with Netscape but when it comes to IE, it doesn't work. It pulls data from the database and populates a number of list boxes. IN IE, it populates only the first list box and doesn't go any further. Depending on the value selected in the first box, it populates the second. From second it populates the 3rd, 4th and 5th boxes.
    Thanks in advance.
    sri

    Let me see if I understand this correctly. You have a servlet running which outputs a dynamic HTML page. It shows up fine under Netscape, but not IE.
    If this is the case, your HTML code probably isn't correct. I'd double-check what you're outputting. This is surprising as that I have found IE to be very leniant.

  • Problem of Java - javascript and javascript - java communicate of same obje

    Hi all,
    I have met a great problem in program an applet! I have tried to communicate between java and javascript and javascript and java in the same page by using jsobject. However, problem occur. It is not a problem to call javascript from java by using jsobject. However, javascript call java by using document.object.function has problem. It cannot find out the object in IE. I have followed the webpage show in java, but the browser still prompt me the object called client not find. Please help!! My html code is shown as follow:
    <HTML>
    <HEAD>
    <TITLE>Alva Final Year Project Demo</TITLE>
    </HEAD>
    <Script language="javaScript">
    function show(html){
    layer.innerHTML = html;
    function getResponse(response){
    alert("response: " + response);
    document.client.getJSCommunicate();
    </Script>
    <BODY>
    <DIV id="layer" style="position:absolute">
    <H2>Secure Server</H2>
    <HR>
    <!--"CONVERTED_APPLET"-->
    <!-- CONVERTER VERSION 1.0 -->
    <OBJECT id="client" classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
    WIDTH = "800" HEIGHT = "400" codebase="http://java.sun.com/products/plugin/1.1.1/jinstall-111-win32.cab#Version=1,1,1,0">
    <PARAM NAME = CODE VALUE = "ClientPart.class" >
    <PARAM NAME="SCRIPTABLE" VALUE="true">
    <PARAM NAME="MAYSCRIPT" VALUE="true">
    <PARAM NAME="type" VALUE="application/x-java-applet;version=1.1">
    <COMMENT>
    <EMBED type="application/x-java-applet;version=1.1" java_CODE = "ClientPart.class" NAME = "client" WIDTH = "800" HEIGHT = "400" pluginspage="http://java.sun.com/products/plugin/1.1.1/plugin-install.html"><NOEMBED></COMMENT>
    </NOEMBED></EMBED>
    </OBJECT>
    <!--
    <APPLET CODE = "ClientPart.class" WIDTH = "800" HEIGHT = "400" NAME = "clientPart" >
    </APPLET>
    -->
    <!--"END_CONVERTED_APPLET"-->
    </DIV>
    </BODY>
    </HTML>
    Thanks your kindly help.
    Alva

    Everthing looks fine to me from here, you should be able to just call the java function direct such as
    document.myAppletObj.doMethod();
    I think your problem could be that your object is called "client". IE can get funny about names, it didn't like me calling a method delete()!!
    Try adding something else to the name such as "my_client", and see if this works any better.
    Chris

  • Live Connect and Java

    Hi All,
    I am a student working on my thesis which is is a Firefox exntension in which users can annotate(i.e. highlight) web content on any web site. I am using Liveconnect to connect javascript and java. All my methods work well, however I noticed an issue that crops up when I create a new instance of something.
    The error I get is in the Java console:
    Ignored exception: java.security.PrivilegedActionException: java.lang.reflect.InvocationTargetException
    the above only occurs for example:
    In my jar file I created a method to send an email:
    Part of the method contains the following:
    public static void main(String[] args) {
           smtp.connect();
           // login using gmail account details
           smtp.login(username,password);
           // create new email message
           EmailMessage message = new EmailMessage();
           message.setTo(to);
           message.setFrom(username);
    } If I comment out EmailMessage message = new EmailMessage() everything works fine, however if not, nothing in the jar file seems to work.
    could you please shed some light on this?
    It is pretty urgent and any input is greatly appreciated
    Kind regards
    Chris

    What is the best way to connect a Java application to
    a remote MySQL server?JDBC.
    I've tried JDBC already. It works great when the
    MySQL server is running on the same machine that the
    application is running on. However, when I specify
    the IP and port of the remote database, I can't
    connect.This usually happens because you haven't configured the security properly, or haven't understood how MySQL security works. It could be something else, though, based on the details you provided.
    I suppose I could have specified the wrong port. How
    can I get the port which the server is running on?Ask the person who set up the server. Or run netstat on the server if it's an orphaned system.
    If I am able to do this connection, are there any
    major security risks? Is there a better way to link
    an application to a remote database?Security risks? For the server or your program?

  • How can I include a portal component look and feel in a java servlet

    Does any body know how can i include a portal component look and feel (tables, buttons, etc) in a java servlet?

    Hi José,
    I don't think that is possible. But you can import the css files that ep uses for its look and feel and try to give your web pages similar look and feel. The tables and other controls used in EP are totally different and are done through complex JavaScript coding instead of simple HTML tags. If you want exact lok and feel then i thin you must go for a Webdynpro based application rather then a J2EE application with JSPs.
    Regards,
    Guru.
    PS: Give points for helpful replies.

  • Avoiding html codes and javascript codes in servlets

    Are there ways to avoid long html codes using out.println() and also javascript codes in servlets? Can I make a jsp and include that file somehow in the servlet and do the processing. Can I get reference to the fields or components declared in the jsp and also do conditional flow based on the buttons present in that jsp.
    Is it possible to include javascript files and instead call that javascript file and also the particular function in that file?
    Please also mention disadvantages if any.

    Javascript is for the client ONLY. Even if you could find a way to use it on the server side, DON'T.
    In my opinion, you should have ZERO logic (except for validation via JavaScript) in your JSP. Have a Servlet do all logic/business rules. The Servlet will create one or more Java Beans that hold ALL dynamic content for a page. Use the Servlets RequestDispatcher to forward the request to the JSP upon completion. The JSP should do nothing more than grab these beans (from the HttpSession object) and fill in the dynamic parts of the page.
    By doing it this way, you seperate the logic and presentation. You can add different 'flavors' (WML, XML) by simplying creating a new JSP page that looks for the same Java Beans, but has different template text.

  • Using Google GWT to create (Dashcode) widgets for iBook Author  I would like to embed interactive widgets in iBooks using iBookAuthor. The widgets in question started life in Java but GWT has allowed them to be converted to javascript and to run on web pa

    I would like to embed interactive widgets in iBooks using iBookAuthor. The widgets in question started life in Java but GWT has allowed them to be converted to javascript and to run on web pages (for example, http://softoption.us/content/node/437 scroll to the bottom). In theory, iBookAuthor can bring in most html5, and much javascript. The technique is to wrap the html in a folder, with 2 extra files, a plist and a default png and then change the extension of the folder to ‘.wdgt’. This is the technique for making Dashboard widgets for the Mac, and Apple even have the Dashcode software to do it. So what you really do is to make a Dashboard widget, then iBookAuthor can import it.  So far, so good. And some  folk have been doing this, for example http://www.prweb.com/releases/2012/2/prweb9242432.htm http://www.panophoto.org/forums/viewtopic.php?f=64&t=10417&p=158330#p158423 However, if you start with GWT and create a single page with one button and a Hello World, compile it, and get the WAR file (I use Eclipse here)… the Safari browser and others will run it properly (even on an iPad). Then if you wrap it, a proper Dashboard widget is created, which runs properly on a Mac. Then if you go to iBookAuthor and put a custom widget in the Text, then drag it in. It is accepted by the text and shown as being there. However, if you use Preview to look at it on an iPad, it is gone (or was never there in the first place). Anyone any ideas on this? [And iBook Author seems to give no warnings.] The widget is at https://dl.dropbox.com/u/46713473/Test6.wdgt.zip I have bells and whistles that I’d like to get into an iBook!
    Thanks for any insights.
    Martin

    I do have a little to add, which might help someone. Indeed, opening a blank page and dragging the widget straight in seems good in difficult cases. But, actually, I was also able to insert successfully from the Toolbar especially to blank pages. So, it may have been something to do with the columns and stuff like that. Anyway back then the insertion would show in iBooks Author but not in the Preview on the iPad. I moved on to actual Google Web Toolkit output javascript. Basically I had three at hand to try: a Hello World with a button which went straight it, one of moderate complexity, (for example with a built in Lisp interpreter), which also went straight in, and finally a more complex one that initially was rejected by iBook Author. Author complained that there was an unsupported media file (of course, Author does not tell you which one it is, that would be too easy). [Remember, this was a proper working Dashboard widget which could be installed on a Mac]. Among other things I had read remarks about .gif files. When looking through the GWT war directory at the actual javascript etc files, I noticed there were two gifs there one called ‘clear.cache.gif ‘  and a second one called  ‘0F89659FF3F324AE4116F700257E32BD.cache.gif’. (Now, there is obfuscation so the numbers here may be different from case to case.) The clear.cache.gif did not seem to be anything special. But the other one is an animation. It is three little boxes that twinkle (rather like a waiting spinning cursor).  So, I opened that file and saved it to itself (that picks the top frame of the animation and saves only that, leaving you with an unanimated gif). The resulting widget drags and drops into iBooks Author (and seems to work properly at a quick glance). So, if you are having trouble with ‘unsupported media files’ converting animated gifs into unanimated gifs might help in some cases.

  • Encrypt in javascript and decrypt in java

    hi guys,
    iam in a strange situation, my requirement is to encrypt the user entered details thr javascript and decrypt in those in java.
    i need some ideas
    thanku

    Why don't you just use SSL? Then the entire communication is encrypted.

Maybe you are looking for

  • Help..Ipod is corrupted. Says to restore but there is no way

    I just updated my ipod(30GB) with new stuff..and suddenly it froze. I unplugged it..plugged it back in..restarted itunes and when i did a box popped up saying that the ipod is corrupted and i need to restore it. But how can i restore it if itunes isn

  • Mail account settings

    My email accounts are not being accepted on Ipad IOS. Gmail worked, but all others claim server incorrect even when identical settings to my MacBook. Any suggestions?

  • Need help with video-scroll

    Hello, I need some help with a project. What I eventually want is that a webcam controls the mouse position and the mouse position controls a video. But first I would like the part where the mouse position controls the video. So if the mouse is on th

  • How to transfer photos from my iphone 5 in my dell lapotop having windows 8 operating system?

    how to transfer photos from my iphone 5 in my dell lapotop having windows 8 operating system?

  • BC4J / Struts application scope

    i have one question: how can I store objects in an application scope. i'd like to store a collection with all users from a viewobject. this collection is used independent from usersessions or requests and can be created when application starts. first