Solved

using println in a Servlet to output HTML page with button that links to another HTML page

Posted on 2004-10-05
10
433 Views
Last Modified: 2013-11-24
Could somebody provide me with a quick and dirty line of code that will output
a HTML button that when clicked allows redirects the user to another page on the website.

I can use println to make webpages, but the quoting required for the HTML is problematic for me inside println(" ") statements
0
Comment
Question by:benk-master-flash
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12227528
System.out.println("<input type=button name=buttob value='Click Me'> onClick=show()");
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12227553
is that what u r expecting??
0
 

Author Comment

by:benk-master-flash
ID: 12227585
OK - it makes the button i want it to link to http://localhost/core/index.jsp
can you make it do that
the onClick=show() syntax??? what is that?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 12

Expert Comment

by:Giant2
ID: 12227637
System.out.println("<INPUT type=\"button\" name=\"TheButtonName\" value=\"Click Here\" onclick=\"doSomething()\">
and soSomething is a script to do someting you want when the button is clicked.

Hope this help you.
Bye, Giant.
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12227660
System.out.println("<Script>");
System.out.println("function show(){");
System.out.println("window.location.href='http://localhost/core/index.jsp'");
System.out.println("}");
System.out.println("</Script>");

System.out.println("<input type=button name=buttob value='Click Me'> onClick=show()");
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12227670
<SCRIPT language="JavaScript">
doSomething(){
window.open("http://localhost/core/index.jsp");
}
</SCRIPT>
0
 
LVL 14

Accepted Solution

by:
sudhakar_koundinya earned 125 total points
ID: 12227717
package org.prithvi.test;

public class Test {
  public Test() {
  }

  public static void main(String s[]) {
    System.out.println("<Script>");
    System.out.println("function show(){");
    System.out.println("window.location.href='http://localhost/core/index.jsp';");
    System.out.println("}");
    System.out.println("</Script>");

    System.out.println(
        "<input type=button name=buttob value='Click Me' onClick='show()'>");

  }
}
0
 

Author Comment

by:benk-master-flash
ID: 12228896
Thank you for your commnets both solutions work.  I have also found the below snippet works well for servlets.
<Script> tag what language is this JavaScript or vbScript
what is a good source of reference on this topic?

String orderformURL =
              response.encodeURL("../OrderForm.jsp");
        out.println
           ("<form action=\"" + orderformURL + "\">\n" +
              "<big><center>\n" +
              "<input type=\"SUBMIT\"\n" +
              "      value=\"Return to Order Form\">\n" +
              "</center></big></form>");

0
 
LVL 12

Expert Comment

by:Giant2
ID: 12234719
>both solutions work

A split could be better.
Thanks.
And sorry for not help you.
Bye, Giant.
0
 
LVL 20

Expert Comment

by:Venabili
ID: 12256509
benk-master-flash,

If two solutions are good for you, you can split the points. Do you want me to reopen it to do this?

Venabili
Java Page Editor
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mockito example issue 8 72
VB Script to add site to Java Exception List 4 76
Desingning Refactoring existing code 2 24
Glassfish admin console not working 1 12
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question