Solved

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

Posted on 2004-10-05
10
432 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
 
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.

861 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now