Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Converting a simple java file to be accessed from a JSP file  RSS feed

 
shreehari Gopalakrishnan
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey masters

i have been working on java past 6 months but still some baby doubts

I have written a program to sort a group of strings


import java.util.Arrays;
import java.util.Comparator;
import java.util.*;
public class TestSort implements Comparator
{
void sortList(String[] list)
{
Arrays.sort(list, this);
for(int i=0;i<list.length;i++) {
System.out.println(list);
}
}
public int compare(Object a,Object b)
{
String first = (String)a;
String second = (String)b;
return first.compareTo(second);
}


public static void main(String[] args)
{ String[] strList= new String[]
{"one","two","three","four","five","six"};
ExSort ex = new ExSort();
ex.sortList(strList);
}}

What i want is i have to write a JSP file which must be populated with some row data and if i click sort it must be sorted

how can i connect the JSP with the above java file ?

To be more clear how can i call this comparator from the JSP

What all the things needed thanks in advance
 
Gunjan Sahay
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try using servlets to handle the sorting functionality. then u can call the servlet from ur jsp file easily.
cheers!
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gunjansahay,

Welcome to JavaRanch!

We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.

Thanks Pardner! Hope to see you 'round the Ranch!
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the JSP forum...
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try using servlets to handle the sorting functionality. then u can call the servlet from ur jsp file easily.


Actually, best practice is the other way around. Perform all your data manipulations in a servlet controller, and then forward control on to the JSP to display the results of the data.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!