?
Solved

pass information from a java application to an asp.net application

Posted on 2003-03-17
24
Medium Priority
?
413 Views
Last Modified: 2010-07-27
say i have a jsp page which is used to authenticate a user login. I need to pass the entered userid and password to an asp.net application called by clicking on a link on the jsp page.

ie. user logs in to a jsp page by entering valid user id and password. upon login he is forwarded to a page that has a link, say 'click-me'. 'click-me' should open an asp.net application running on another server, pass in the user id and pasword entered in the jsp page, so that the usrr can be authenticated in the asp.net application.
any takers??
0
Comment
Question by:krisme77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 5
  • 3
  • +3
24 Comments
 

Expert Comment

by:ashutoshleo
ID: 8154677
are u looking for this..


<HTML>

<HEAD>
<TITLE>fgdfg</TITLE>



<%
String user = request.getParameter("user");
String password = request.getParameter("password");


if (user.equals("dff") && password.equals("dsfdsf"))
{  
session.setAttribute("userName",user);  
session.setAttribute("passwd",password);  
response.sendRedirect("asa.jsp");
}
 else
{
session.invalidate();
response.sendRedirect("login.jsp");
   //message=messageIncorrect;
}

%>
</HEAD>

<BODY>

<h2><font color="#AA0000">Ummmmm</font></h2>

</BODY>

</HTML>
0
 

Author Comment

by:krisme77
ID: 8154813
i don't think so..what u have sent me is, how to validate a user and redirect him/her to a jsp page..my question is, how to pass information from a jsp page to a asp.net application.
0
 

Expert Comment

by:ashutoshleo
ID: 8154975
Use exec() method of Runtime class as following and call that application


Process child;
          serverMessage=new StringBuffer(2000);
              try
             {
                      child= Runtime.getRuntime().exec("c://application.exe send "+address+" "+ message);
              }
              catch( Exception e )
              {
                       e.printStackTrace();
                  }
             
              InputStream x;
                try
                {
                   x = child.getInputStream();// TO GET OUTPUT
                }
                catch( Exception e )
                {
                       e.printStackTrace();
                  }

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:krisme77
ID: 8155021
u lost me here..u most definitely know what u r talking about, but i don't.:).could pls tell me where exactly in the above, r u passing the userid and password??
0
 

Expert Comment

by:ashutoshleo
ID: 8155026
sorry the exxact call willbe like this-
try
            {
                     child= Runtime.getRuntime().exec("c://application.exe "+user);//
             }
             catch(...

i copied it from one of my codes and forgot to delete existing words
0
 

Author Comment

by:krisme77
ID: 8155051
my asp.net application will not be residing in the same server as the jsp..it will be on another server and can be accessed via ip..
0
 
LVL 2

Expert Comment

by:functionpointer
ID: 8156692
since the 'click me' page is generated by your servlet, easiest way is to custom write the url pointing to the ASP server with the username and password like:

<% String username = request.getParameter("username");
   String password = request.getParameter("password");
   String href = "http://aspserver/login.asp?username=" + username + "&password=" + password;
   href = response.encodeUrl( href );
%>

then,

<a href="<%= href %>">click me</a>


a better solution would be to write the username and passwords as hidden form inputs to keep the username and password off the URL, and the ASP server may require an HTTP method POST for login. something like:
<% String username = request.getParameter("username");
   String password = request.getParameter("password");
%>
<form id="aspLogin" method="POST" action="http://aspserver/login.asp">
<input type="hidden" name="username" value="<%=username%>">
<input type="hidden" name="password" value="<%=password%>">
<a href="#" onclick="document.aspLogin.submit();">click me</a>
</form>

either will work just fine for what you described.

good luck :)
0
 
LVL 1

Expert Comment

by:Yawgmoth
ID: 8156749
Have your JSP page POST the data to the ASP page, you can pass it in hidden fields
0
 
LVL 2

Expert Comment

by:functionpointer
ID: 8156757
umm, yeah.  i thnk i just said that, didn't i?
0
 

Author Comment

by:krisme77
ID: 8160908
functionpointer ,
 i tried the way u suggested, but when i click on 'click me' i'm not redirected to login.asp. what am i doing wrong??and, how do i capture the values of username and password in login.asp??
0
 

Author Comment

by:krisme77
ID: 8160933
also, how do i pass values to the hidden fields usrname and password in the jsp page??
0
 

Author Comment

by:krisme77
ID: 8161009
also, how do i pass values to the hidden fields usrname and password in the jsp page??
0
 

Author Comment

by:krisme77
ID: 8161300
also, how do i pass values to the hidden fields usrname and password in the jsp page??
0
 
LVL 2

Expert Comment

by:functionpointer
ID: 8161402
>>when i click on 'click me' i'm not redirected to login.asp. what am i doing wrong??

try it the first way, until you get the rest working.

>>how do i capture the values of username and password in login.asp
I was assuming you already had a 'login.asp' page in your .NET app, and just emulating its behavior. You should make the hidden vars on the click me jsp look just like the 'login.asp', so the asp server doesnt know the difference.

>>also, how do i pass values to the hidden fields usrname and password in the jsp page??

just like i showed you.
i am assuming you have a 'login.jsp' somewhere with at least something like:
<form method="POST" action="clickmepage.jsp">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" value="login">
</form>

clickmepage.jsp would have:
<% String username = request.getParameter("username");
  String password = request.getParameter("password");
%>
0
 

Author Comment

by:krisme77
ID: 8161451
i have a login.aspx page simulating a jsp page for now with,

<form id="Form1" action=http:\\myserver\Form2.aspx method="post" runat="server">
<input type="hidden" name="username" value="krishnan">
<input type="hidden" name="password" value="password">
<a href=http:\\myserver\Form2.aspx onclick="document.Form1.submit);">click me</a>
</form>

in my Form2.aspx page, i have 2 labels to capture and display username and password text,
this.Label1.Text=Request.ServerVariables["username"];
this.Label2.Text=Request.QueryString["password"];

but i am not getting the values of username and password. I don't want to pass the values as a part of the url as then they wil be exposed.
0
 

Author Comment

by:krisme77
ID: 8161453
also, how do i pass values to the hidden fields usrname and password in the jsp page??
0
 

Author Comment

by:krisme77
ID: 8161498
also, how do i pass values to the hidden fields usrname and password in the jsp page??
0
 
LVL 2

Expert Comment

by:functionpointer
ID: 8163796
>> <a href=http:\\myserver\Form2.aspx onclick="document.Form1.submit);">click me</a>

I dont think you can do this. href takes precedence, onclick will never happen. try href="#", then onClick="document.Form1.submit();".  or shortcut the whole thing for the sake of getting it running and put a submit button on it!

As far as the Form2.aspx, I am not sure how ASP handles the elements of a HTTP POST. In a java servlet, the request.getParameter() is blind to the method. it works for GET and POST the same.



>>also, how do i pass values to the hidden fields usrname and password in the jsp page??

maybe i am not clear what you mean. i showed you how to write the hidden elements in the jsp page. From there, they are just HTML and become part of a HTTP post request submitted by the form after the click.
0
 
LVL 1

Expert Comment

by:Yawgmoth
ID: 8164199
Functionpointer pretty much explained it to you look for something like this in his code since he pretty much already wrote it for you

<Input type=hidden name= something>

then in your login form to get the value of something you do request.Form("something") is this what you were looking for?  
0
 

Author Comment

by:krisme77
ID: 8166738
functionpointer, I tried like u suggested and made href="#". but then, though the form seems to submit ti does'nt redirect to Form2.aspx upon submission. I am still at the login page.
0
 
LVL 2

Accepted Solution

by:
functionpointer earned 260 total points
ID: 8171919
Ok. Lets try this:
Here is a very simple login page in asp named test1.asp.

<html><body>
<form name="form1" method="POST" action="http://localhost/test2.asp">
  <a href="#" onclick="document.form1.submit();"> Click Me </a><br>
  user:<input type="text" name="username"><BR>
  password:<input type="password" name="password"><BR>
  <input type="submit">
</form>
</body></html>

It submits the form to this test2.asp, which rewrites the username/password fields.

<html><body>
<form name="memberLoginForm" id="memberLoginForm" method="post" action="http://www.experts-exchange.com/Programming/Programming_Languages/Java/jsp/memberLogin.jsp">
<a href="#" onclick="document.memberLoginForm.submit();"> Click Me </a><br>
<input type="hidden" name="redirectURL" value="/Programming/Programming_Languages/Java/Q_20553909.html">
<input type="hidden" name="loginMemberName" value="<%= Request.Form( "username" ) %>">
<input type="hidden" name="loginPassword" value="<%= Request.Form("password") %>">
<input type="submit" value="Login">
</form>
</body></html>

Stick these 2 files in your Inetpub/wwwroot. Clicking submit on test2.asp will effectively log you in to experts-exchange, that is if you provided the right username and password to test1.asp. This is about as plain as I can make it. It just works. If it didn't, I couldn't have just logged in to post this.  ;)

experts-exchange, forgive my abuse of the login. I used this as an example with the only the best intentions. have mercy on a tired guy to lazy to surf for another login mechanism in jsp. :)
0
 

Expert Comment

by:CleanupPing
ID: 9058633
krisme77:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9726982
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept functionpointer's comment as answer.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jimmack
EE Cleanup Volunteer
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

770 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