Results 1 to 5 of 5
  1. #1
    ajincoep is offline Member
    Join Date
    Aug 2010
    Posts
    10
    Rep Power
    0

    Default how to use window.open(...) in a jsp to call a servlet and open jsp in a new window.

    Hi All,

    Data is retrived by the servlet and then it calls a jsp to show data. As mentioned the jsp should be called in a new window.

    Could u please tell me how we do it?

    Thnx.

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    618
    Rep Power
    4

    Default

    Hi. What do you have problem? You can create button. When you click it show new window.
    Java Code:
    <INPUT type="button" value="New Window!" onClick="window.open(needUrl,'mywindow','width=400,height=200')">
    Where needUrl - url your servlet It after run redirect to jsp. It is easy.
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    ajincoep is offline Member
    Join Date
    Aug 2010
    Posts
    10
    Rep Power
    0

    Default

    Hi Petr,
    Thanks 4 reply,

    I tried to mention path of a servlet as mention below, but is not working. What is the mistake i am doing?
    Java Code:
    <INPUT type="button" value="New Window!" onClick="window.open(RequestProcessor,'mywindow','width=400,height=200')">

    My Servlet info

    Java Code:
    <servlet-name>RequestProcessor</servlet-name>
        <servlet-class>com.retailbank.controller.RequestProcessor</servlet-class>
      </servlet>
      <servlet-mapping>
        <servlet-name>RequestProcessor</servlet-name>
        <url-pattern>/Module.do</url-pattern>
      </servlet-mapping>

    Also there are some hidden parameters that the servlet uses to pass the request to appropriate class.

    Java Code:
    <input type="hidden" name="moduleName" value="account">
    <input type="hidden" name="trasferType" value="transaction">

    I hope the request object will carry this parameters.

  4. #4
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    618
    Rep Power
    4

    Default

    You need replace RequestProcessor to "/Module.do".
    About parameters you can create function js. which build need url.
    for example
    Java Code:
    var needUrl = "/Module.do?"
    function buildUrl() {
        var moduleName = document.getElementById("moduleIdEl");
        needUrl += "moduleName=" + moduleName.value;
        var trasferType = document.getElementById("trasferTypeIdEl");
        needUrl += "&trasferType=" +trasferType.value;
    }
    
    ...
    window.open(needUrl, ...
    Last edited by Petr; 02-04-2011 at 10:08 AM.
    Skype: petrarsentev
    http://TrackStudio.com

  5. #5
    ajincoep is offline Member
    Join Date
    Aug 2010
    Posts
    10
    Rep Power
    0

    Default

    Sorry for the delayed response.
    But the thing is not actually working.

    Java Code:
    var moduleName = document.getElementById("moduleIdEl");
    Nothing is getting populated under var moduleName . I also tried getElementByName but not working.
    Java Code:
    var moduleName = document.getElementByName("moduleName");
    One more error i get after directly constructing the url like
    needUrl=/Module.do?accountName=account&transferType=transac tion

    HTTP Status 405 - HTTP method GET is not supported by this URL

    Java Code:
    public void doPost (HttpServletRequest req,
    			HttpServletResponse res)
    	throws ServletException, IOException, NullPointerException
    	{	
    		dispatcher = getServletContext().getRequestDispatcher(reqMapperObj.mapRequest(req));
    		if(dispatcher!=null)
    			dispatcher.forward(req,res);
    		else			
    			System.out.println("No Dispatcher found");
    	}
    
    	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    	  {
    	    doPost(request, response);
    	  }


    This is the jsp for your ref

    Java Code:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <%@ page import="com.retailbank.domain.accounts.Statement,com.retailbank.domain.accounts.Transaction,java.util.List,java.util.ArrayList" %>
    <% Statement statement=(Statement)request.getAttribute("statement");%>
    <%request.setAttribute("statement",statement); %>
    <% Transaction transaction=(Transaction)request.getAttribute("transaction");%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <style type="text/css"><%@include file="/css/RetailPOC.css" %></style>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Statement</title>
    
    <script type="text/javascript">
    
    var needUrl = "Module.do?";
    function buildUrl() {
    	document.getElementsByName("moduleName");
        var moduleName = document.getElementsByName("moduleName");
        needUrl += "moduleName=" + moduleName.value;
        var trasferType = document.getElementsByName("transferType");
        needUrl += "&trasferType=" +trasferType.value;
        needUrl = "Module.do?moduleName=account&transferType=transaction";
        
    }
    </script>
    
    </head>
    <body>
    <%@ include file="account_landing.jsp" %>
    <form name="formStatement" action="Module.do" method="GET" >
    <input type="hidden" name="moduleName" value="account">
    <input type="hidden" name="trasferType" value="transaction">
    <input type="hidden" name="accountid" value="<%=statement.getAccount().getAccountId() %>"></input>
    
    <script type="text/javascript">
    buildUrl();
    </script>
    
    <table class="table1">
    <th> TransactionId</th>
    <th> AccountId </th>
    <th> AccountType </th>
    <%int row=1;%>
    <% for(int i=0;i<statement.getTransaction().size();i++){ %>
    <tr class="row<%=row%>">
    <td><a href="#" onclick="window.open(needUrl,'mywindow','width=400,height=200')"> <%=statement.getTransaction().get(i).getTransactionId()%></a></td>
    <td><%=statement.getAccount().getAccountId()%></td>
    <td><%=statement.getAccount().getAccountType()%></td>
    	<% row++;%>
    	<%}%>
    </tr>	
    </table>
    </form>
    
    
    </body>
    </html>

Similar Threads

  1. Open a new window and drawing map into it
    By cselic in forum AWT / Swing
    Replies: 2
    Last Post: 08-27-2010, 11:23 AM
  2. window.open problem
    By praveenkumar14 in forum NetBeans
    Replies: 2
    Last Post: 10-12-2009, 11:18 AM
  3. how to open an internet Window
    By loa41 in forum New To Java
    Replies: 3
    Last Post: 07-30-2009, 05:20 AM
  4. My first post, how to open 2nd window?
    By Grom in forum NetBeans
    Replies: 6
    Last Post: 08-17-2008, 03:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •