File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Very tricky question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Very tricky question" Watch "Very tricky question" New topic
Author

Very tricky question

Gaurav Chikara
Ranch Hand

Joined: Jun 09, 2000
Posts: 410
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


SCJP,SCWCD,SCBCD<br />If Opportunity doesn't knock then build the door
narayan kulkarni
Greenhorn

Joined: Jan 31, 2001
Posts: 17
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

Take up computer programming as fun and you will just enjoy it. Always keep in mind that in some way your program is going to make human life easier.
Gaurav Chikara
Ranch Hand

Joined: Jun 09, 2000
Posts: 410
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

Joined: Jan 04, 2001
Posts: 71
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

Joined: Jun 09, 2000
Posts: 410
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).]

 
Consider Paul's rocket mass heater.
 
subject: Very tricky question