aspose file tools*
The moose likes JSP and the fly likes Help Needed For JSP code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Help Needed For JSP code" Watch "Help Needed For JSP code" New topic
Author

Help Needed For JSP code

Upendra Bhole
Greenhorn

Joined: Dec 05, 2004
Posts: 22
Dear Sir/Madam

The code you have given in that the ip to be ping is hard coded.But actually I want to make it as variable,
See the following code and suggect me in the second jsp what i have to change.


First I made the table name pingip

1)
select * from pingip
atmid name atmip routerip
------- ------- ------- ---------
S1AC0635 abc 198.24.37.7 198.24.37.7
S1AN0631 abc1 187.25.16.2 187.25.16.2

2)
<HTML>
<HEAD>
<center>
<H1>Enter The Station ID<H1>
</HEAD>
<BODY>
<form action="http://localhost:8100/pingip.jsp">
<table border =1 cellpadding=0>
<TR>
<TD><H4>ATM ID :</H4><input type="text" name ="a"></TD>

</TR><BR></table><br>
<INPUT TYPE="submit" value="Ping ATMIP" STYLE="COLOR:BLUE" align = centre>
</center>
</form>
</BODY>
</HTML>

3)

<%@page import="java.io.*"%>
<%@page import="java.sql.*"%>
<%@page import="java.lang.*"%>
<%
String aip = request.getParameter("a");
response.setContentType("text/plain");
try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc.odbc:ash","","");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select atmip from pingip where atmid='"+aip+"'");
Runtime r = Runtime.getRuntime();
Process p = r.exec("ping ");
InputStream ins =p.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(ins));
String s = br.readLine();
while(s != null)
{
out.println(s);
System.out.println(s);
s = br.readLine();
}

con.close();
}//end of try



catch(SQLException eb)
{
out.println(eb.getMessage());
}//end of catch
catch(Exception ea)
{
out.println(ea.getMessage());
}//end of catch


%>


---------

From First jsp I will put in the textbox atm id S1AC0635.Now if i want to ping ip 198.24.37.7 what could be the change in my sencond jsp especially in

Process p = r.exec("ping ");
So that I can ping any ip from database table "pingip"
Please suggest me.

Upendra
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
Pass it into the page as a variable, and concatenate that variable to the String you pass to the exec method:




This would apply if your JSP page is called MyPage.jsp, so you would type the following into your browser:

MyPage.jsp?address=192.144.3.1

to ping 192.144.3.1
Upendra Bhole
Greenhorn

Joined: Dec 05, 2004
Posts: 22
Thanks for your reply.
The code which you have given in that you are passing the ip in text box and that ip you are accessing in second page and inserting into the exec method.

But I am not passing ip in text box in first page.
My doubt is that how i will pass the out put of query ResultSet into the
exec method.ie whatever the value stored inthe ResultSet object rs that value I want to pass into exec method.Below logic I have applied but it is not working.Please suggect me with code.
.
.
.
ResultSet rs = st.executeQuery("select atmip from pingip where atmid='"+aip+"'");
Runtime r = Runtime.getRuntime();
Process p = r.exec("ping" +rs);
.
.


Regards
Upendra
hassan mahmood
Greenhorn

Joined: Jan 15, 2003
Posts: 17
Below is the correct code........

ResultSet rs = st.executeQuery("select atmip from pingip where atmid='"+aip+"'");
Runtime r = Runtime.getRuntime();
rs.next();
String ip = rs.getString(0);
Process p = r.exec("ping " +ip);


Hassan
SCJP2
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Whatever. Its a bad idea to write JDBC code inside JSP. JSP is meant for presention though.
Upendra Bhole
Greenhorn

Joined: Dec 05, 2004
Posts: 22
Thanks for your suggestion.
I have tried for the same code as you suggest me.
It is giving the error as below.

[Microsoft][ODBC Driver Manager] Invalid descriptor index


Upendra
Upendra Bhole
Greenhorn

Joined: Dec 05, 2004
Posts: 22
Can any body help me.
Please

Upendra
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Upendra,

I think for getting ip you should try it as



in any case do remember what adeel said...

presentation layer should not contain any JDBC or code related to database.
It is not considered as good practice

thanks
Shailesh


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Upendra Bhole
Greenhorn

Joined: Dec 05, 2004
Posts: 22
Thaks for your reply.
But when I insert the s1ac0635 in text box then i tried.

.
.
String ip = rs.getString(1);
.
.

it gives out put in browser as below

create process: ping198.24.37.7 error=2

Instead of pinging characteristics...

Please

Upendra
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
Originally posted by Upendra Bhole:


it gives out put in browser as below

create process: ping198.24.37.7 error=2

Instead of pinging characteristics...

Please

Upendra



Look at the code



leave a whitespace between " & ping like "ping "

hth
-MB
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help Needed For JSP code