This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Very tricky question

 
Gaurav Chikara
Ranch Hand
Posts: 412
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks
I tried my best but cud not come to any conclusion
Can any one tell me that if on click of submit button when i call a servlet .if i want that servlet to be opened in a new window instead of the same browser is it possible
if yes cana anyone pls tell me how it is possible
i tried it thru calling a function on the event onSubmit but that also donot serve the purpose
Thnkx in advance for any of your views
Gaurav
 
narayan kulkarni
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its possible using Javascript
I exactly do not know the syntax in Javascript
it should be like window .open() which opens a new window and I hope you can also pass the pass the url as parameter of the servlet that you would want to be evoked or a html pages
Regards
 
Gaurav Chikara
Ranch Hand
Posts: 412
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi narayan
i appreciate ur reply
but thru javascript it is only possible if we are not using submit button but i m using submit button and on its click
only one operation is performed and that is invoking of the servlet with in same browser
so my problem is still confusing even if i use onClick on submit button then also popup window opens but simultanously the servlet gets called with in the same browser
any other views are welcome
Gaurav
Originally posted by narayan kulkarni:
Its possible using Javascript
I exactly do not know the syntax in Javascript
it should be like window .open() which opens a new window and I hope you can also pass the pass the url as parameter of the servlet that you would want to be evoked or a html pages
Regards

 
Ajan Balakrishnan
Ranch Hand
Posts: 71
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just tried this for you. The following is the html and servlet code for your perusal. I think it meets your requirement(opens servlet in a new window)
HTML Code
----------
<HTML>
<HEAD>
<TITLE>TESTING</TITLE>
</HEAD>
<BODY bgcolor=white>
<FORM name="Form" onSubmit="return func();" >
<center><b>
ID Number:�<input type="text" name="Userid" value="Ajan" SIZE=20 MAXLENGTH=9 ><br>
Password���:�<input type="password" name="Password" value="ferrari" SIZE=20><br>

</B></center>
<h1 align=right>
<input type="submit" value="Done">
<input type="Reset" value="Cancel">
</h1>

</FORM>

<Script language="JavaScript" >

function func()
{
var var1 = Form.Userid.value;
var var2 = Form.Password.value;
var var3 = "http://localhost:8080/servlet/PostServlet?Userid="+ var1 +"&Password="+ var2;

window.open(var3, "hello");
return true ;
}

</script>

</BODY>
</HTML>
Servlet Code
------------
import java.io.IOException;
import java.io.*;
import java.util.Properties;
import javax.servlet.*;
import javax.servlet.http.*;
public class PostServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException
{
doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException
{
String userId = request.getParameter("Userid");
String password = request.getParameter("Password");
PrintWriter out = response.getWriter();
out.println(userId);
out.println(password);

}
}

Hope this helps

Ajan
[This message has been edited by Ajan Balakrishnan (edited February 01, 2001).]
[This message has been edited by Ajan Balakrishnan (edited February 01, 2001).]
 
Gaurav Chikara
Ranch Hand
Posts: 412
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thnkx ajan
it really resolved my doubts
i m thankful to ya
have a nice day
Gaurav
Originally posted by Ajan Balakrishnan:
I just tried this for you. The following is the html and servlet code for your perusal. I think it meets your requirement(opens servlet in a new window)
HTML Code
----------
<HTML>
<HEAD>
<TITLE>TESTING</TITLE>
</HEAD>
<BODY bgcolor=white>
<FORM name="Form" onSubmit="return func();" >
<center><b>
ID Number:�<input type="text" name="Userid" value="Ajan" SIZE=20 MAXLENGTH=9 ><br>
Password���:�<input type="password" name="Password" value="ferrari" SIZE=20><br>

</B></center>
<h1 align=right>
<input type="submit" value="Done">
<input type="Reset" value="Cancel">
</h1>

</FORM>

<Script language="JavaScript" >

function func()
{
var var1 = Form.Userid.value;
var var2 = Form.Password.value;
var var3 = "http://localhost:8080/servlet/PostServlet?Userid="+ var1 +"&Password="+ var2;

window.open(var3, "hello");
return true ;
}

</script>

</BODY>
</HTML>
Servlet Code
------------
import java.io.IOException;
import java.io.*;
import java.util.Properties;
import javax.servlet.*;
import javax.servlet.http.*;
public class PostServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException
{
doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException
{
String userId = request.getParameter("Userid");
String password = request.getParameter("Password");
PrintWriter out = response.getWriter();
out.println(userId);
out.println(password);

}
}

Hope this helps

Ajan
[This message has been edited by Ajan Balakrishnan (edited February 01, 2001).]
[This message has been edited by Ajan Balakrishnan (edited February 01, 2001).]

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic