This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes JSP and the fly likes JSP execute java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP execute java program" Watch "JSP execute java program" New topic
Author

JSP execute java program

Sean sia
Greenhorn

Joined: Aug 28, 2012
Posts: 3
Morning! i am new to JSP and i need to create a JSP program. Can anyone assists me?Below is my java class and method.

public class BusinessRecord{
.....
public static Connection connecString(String conn){
......
return(con);
}

public static void main(String [] args) throws IOException{
constr = connect(c_str);
.....
try{
ResultSet rset = null;
Statement stm;
String sql = "SELECT ProductID FROM Tezco";
stm = constr.createStatement();
rset = stm.executeQuery(sql);
while(rset.next()){
String ProductID = rs.getString("ProductID");

System.out.print("ID " + ProductID);
}
rs.close();
}catch(SQLException e){
.......
.....
}

}




thank you.
R. Jain
Ranch Hand

Joined: Aug 11, 2012
Posts: 367
    
    1

Sean sia wrote:Morning! i am new to JSP and i need to create a JSP program. Can anyone assists me?Below is my java class and method.

public class BusinessRecord{
.....
public static Connection connecString(String conn){
......
return(con);
}

public static void main(String [] args) throws IOException{
constr = connect(c_str);
.....
try{
ResultSet rset = null;
Statement stm;
String sql = "SELECT ProductID FROM Tezco";
stm = constr.createStatement();
rset = stm.executeQuery(sql);
while(rset.next()){
String ProductID = rs.getString("ProductID");

System.out.print("ID " + ProductID);
}
rs.close();
}catch(SQLException e){
.......
.....
}

}


thank you.


Well, you told that you want a JSP program.. But you need to tell what you want that JSP page to do. (because the simplest JSP program is a blank page saved with extension .jsp)
Be clear in whatever you are asking to get Valuable Input from others..

And yes, UseCodeTags to quote your code.. It will be easy for others to read.. :D
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60074
    
  65

JSPs aren't programs, per se. They are the template components of a web application. You do not "run" JSPs via Java code that has a main method.

I'd recommend grabbing a good modern book on Servlets and JSP and start learning.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sean sia
Greenhorn

Joined: Aug 28, 2012
Posts: 3
Hi, R.Jain.
sorry for did not mentioned clearly. from ithe program i have, i would like to display the output from the java program which initially the java program display. So when i create the jsp page, wat do i nid to do when i hv the jsp tag? How do i execute the java program and display the result in jsp page without translate entire code i hv in java into jsp?

Hi, Bear Bibeault.
i will do it.

Thank you.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60074
    
  65

Sean sia wrote:Hi, R.Jain.
sorry for did not mentioned clearly. from ithe program i have, i would like to display the output from the java program which initially the java program display.

Read my reply again. JSP is not something you use with a "normal" Java program. It must be part of a web application

wat do i nid to do when i hv the jsp tag? How do i execute the java program and display the result in jsp page without translate entire code i hv in java into jsp?

You should never put Java code into a modern JSP. So don't even think of doing that.

Also, Please use real words when posting to the forums. Abbreviations such as "wat" in place of "what" and "hv" in place of "have" only serve to make your posts more difficult to read and less likely to generate useful responses.

Please click this link ⇒ UseRealWords for more information.
Sean sia
Greenhorn

Joined: Aug 28, 2012
Posts: 3
Hi Bear Bibeault ,

i have read some book and i actually get more understanding. Thanks for the information as well as advice which i appreciate it.

Thank you.
 
 
subject: JSP execute java program
 
Similar Threads
SQL exception:could not resolve service name
why ejbCreate can't be invoked?
How to return class instance?
Bug in JDBC ? Simple Select statement not returning a resultSet
need to transfer productID from url to action class in struts 2