Warning for java developers Solve this problem if u are a java expert

MY problem is this:

I am developing a software for NDPL company ( i m on training) i have got a serious problem.I want to send the data using post method i.e. i want that no one could see the parameters i m sending . Problem is that i m sending this by a href link :

<% Connection con5 = DriverManager.getConnection("jdbc:microsoft:sqlserver://kapoor-b309553d","sa","tiger");

String q5 = "select distinct location from hall" ;

Statement stmt5 = con5.createStatement();

ResultSet rs5 = stmt5.executeQuery(q5);

while(rs5.next()){

str5= rs5.getString("location");

%>

<tr><td class="menuNormal">

<a HREF="resource.jsp?resource=location&common=<%=str5%>&user=<%=user%>&admin=<%=admin%>" class="menuitem" ><%=str5%></a>

</td></tr>

% } %>

NOW TELL ME IS THEIR ANY WAY HERE SO THAT THE PARAMETERS USER , ADMIN IS SEND TO OTHER PAGE WITHOUT DISPLAY THEM ON THE URL , (I THINK THEIR IS NO WAY TO DO THIS) . PROVE ME

AND GET A CROWN OF JAVA EXPERT REALLY OF A JAVA EXPERT FROM ME. I HAIL YOU FOR MY REST OF LIFE

[1191 byte] By [himanshu_kapoora] at [2007-10-3 2:07:24]
# 1

You do realize that HTML has absolute NOTHING to do with Java? It's just content generated by your java code, after that its all browser magic.

Well here is your solution: in stead of using an url, use a form with a POST method to submit the values in stead of a clickable link. Using javascript you can even automatically submit said form, something like this:

<body onload="document.myform.submit();">

...

<form name="myform" method="post" action="resource.jsp">

<input type="hidden" name="resource" value="location">

<input type="hidden" name="common" value="<%str5%>">

...

</form>

...

</body>

The key here is the POST request, that will make it so that the parameters will not end up in the url.

gimbal2a at 2007-7-14 19:06:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Hmm I can figure out from your code that u r on training.

1) My first tip is that dont make the connection code in jsp. Make a common java connection class. Read the username and password from a properties file. Cos if u code this in each jsp and u need to change the password then ur gonna increase ur development time.

2) Simply use POST mechanism and use hidden parameters in ur jsp.

URL rewriting is visible to everyone.

>PROVE ME AND GET A CROWN OF JAVA EXPERT REALLY OF A JAVA EXPERT FROM ME. I HAIL YOU FOR MY REST OF LIFE

;-) I would certainly not rate this question for a "JAVA EXPERT". You've got a long way to go buddy .. all the best

RohitKumara at 2007-7-14 19:06:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

hey gimbal2,

Thanks , but...

You r doing a logical mistake in this because see my code is in the while loop i.e. i m retrieving data from the database but by ur pseudo form method only the last retrieve data store in str5 and all the preceeding data lost so i always send the last of my database entry . and i have to send the different location . Think u will find that u r wrong because i knew this method , that's why i m saying to u this.

Thanks

himanshu_kapoora at 2007-7-14 19:06:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Hey Mr. RohitKumar (Brother coz my brother name is same)

First i say sorry if my title hurts you . Sorry........

Second , Sir i wanted to say (by my code) that is their any java expert who can send the hidden data using hypertext link . Because see my logic , i m retreiving data from the database and every time i have to set a new value in str5. Literally i want to make a drop down link.Like i want to show the client that the following resources are available and when client click on a link then he will see a window regarding to that resource. It's a resource management project.

himanshu_kapoora at 2007-7-14 19:06:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Hi Friend,

I'm not a big java coder (My Guruji already knows it)

I am a 'rookie' like you....

In the below method suggested i've taken help of AJAX.

I am aware it is not a comeplete solution for your problem but you can definately try this as a workaround.

In the example instead of using a hyperlink to a specified url i've taken help of javascript to send out the REQUEST parameters U want......

But in this case there is a possiblity of viewing those parameters in the status bar...

Which cud be again disabled using javascript....

Though i'm sending a http-get request the beauty of this technology is that it would not display the URL either on the address bar or on the status bar....

YOUR CODE AFTER RESTRUCRING:

=================================

<%@page language="java" import="java.sql.*" %>

<html>

<head>

<script language= 'javascript'>

var xmlHttp

function StoreSession(str,str1,str2,str3)

{

xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)

{

alert ("Browser does not support HTTP Request")

return

}

var url="StoreSession.jsp"

url=url+"?resource="+str

url=url+"&common="+str1

url=url+"&user="+str2

url=url+"&admin="+str3

url=url+"&sid="+Math.random()

xmlHttp.onreadystatechange=stChange

xmlHttp.open("GET",url,true)

xmlHttp.send(null)

}

function stChange()

{

if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){

location.assign("resource.jsp");

}

}

function GetXmlHttpObject()

{

var objXMLHttp=null

if (window.XMLHttpRequest){

objXMLHttp=new XMLHttpRequest()

}

else if (window.ActiveXObject){

objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")

}

return objXMLHttp

}

</script>

</head>

<body>

<% Connection con5 = DriverManager.getConnection("jdbc:microsoft:sqlserver://kapoor-b309553d","sa","tiger");

String q5 = "select distinct location from hall" ;

Statement stmt5 = con5.createStatement();

ResultSet rs5 = stmt5.executeQuery(q5);

while(rs5.next()){

str5= rs5.getString("location");

%>

<tr><td class="menuNormal">

<a HREF="javascript:StoreSession('location','<%=str5>','<%=user>','<%=admin%>')" class="menuitem"><%=str5%></a>

</td></tr>

% } %>

</body>

</html>

CODE FOR StoreSession.jsp:

==========================

<%

String resource=request.getParameter("resource");

String common=request.getParameter("common");

String user=request.getParameter("user");

String admin=request.getParameter("admin");

session.setAttribute("resource",resource);

session.setAttribute("common",common);

session.setAttribute("user",user);

session.setAttribute("admin",admin);

out.println("<br>");

%>

CODE FOR resource.jsp:

==========================

<%

String user=session.getAttribute("user").toString();

String admin=session.getAttribute("admin").toString();

out.println(user+""+"admin);

%>

If the following approach do not resolve your issue i am sure there would definately be a tricky solution existing for the problem.

NOTE:We need to ma ke sure that we are using a browser which supports XML(eg:IE5.0+,Mozilla Firefox)

REGARDS,

RAHUL

RahulSharnaa at 2007-7-14 19:06:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

This is what you want to do

Write a javascript funciton like this

// Capture the row number of the link clicked in a hidden var

function submitLink( rowNo ) {

document.form.rowNo.value=rowNo;

document.form.submit();

}

<FORM NAME="form" ACTION="resource.jsp" METHOD="post">

while(rs.next()) {

<TR>

<A HREF="#" onClick="submitLink(<%=i%>) ">

<INPUT TYPE="hidden" NAME="common" VALLUE="<%=str5%>

</TR>

}

<INPUT TYPE="hidden" NAME="rowNo">

</FORM>

====IN resource.jsp

String rowNo = request.getParameter("rowNo");

int iRowNo = Integer.parseInt(rowNo);

String allCommons[] = request.getParameterValues(common);

String myCommon = allCommons[iRowNo];

bhayzonea at 2007-7-14 19:06:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

hello guys u r so good (hi hi )

please solve this problem ,,

i have create three file in the same package p1

protec.java

package p1;

public class protec

{

int n = 1;

protected int n1 = 2;

private int n2 = 3;

public int n3 = 4;

public protec()

{

System.out.println(" Base const.");

System.out.println(" n_pro = " +n1);

System.out.println(" n_pri = " +n2);

System.out.println(" n_pub = " +n3);

System.out.println(" n " + n);

}

}

derive.java

package p1;

class derive extends protec

{

derive()

{

System.out.println("derived constructor");

System.out.println(" n = " +n);

// class only

//System.out.println("n_pri "+ n_pri);

System.out.println("n_pro "+ n1);

System.out.println(" n_pub "+ n3);

}

}

sample.java

package p1;

class sample

{

sample()

{

protec p = new protec();

System.out.println(" same package const.");

System.out.println(" n_pro = " + n1);

//class only

//System.out.println(" n_pri = " + n2);

System.out.println(" n_pub = " + n3);

System.out.println( " ");

}

}

now when i compile protec.java it compiles. But................

when i compile derive .java then it gives me following error

I:\JAVA\p1>javac derive.java

derive.java:3: cannot find symbol

symbol: class protec

class derive extends protec

^

derive.java:8: cannot find symbol

symbol : variable n

location: class p1.derive

System.out.println(" n = " +n);

^

derive.java:13: cannot find symbol

symbol : variable n1

location: class p1.derive

System.out.println("n_pro "+ n1);

^

derive.java:14: cannot find symbol

symbol : variable n3

location: class p1.derive

System.out.println(" n_pub "+ n3);

^

4 errors

why guys why?

please help meeeeeeeeeeeeeeeeee

Thanks

himanshu_kapoora at 2007-7-14 19:06:16 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...