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.
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.
Hi. What do you have problem? You can create button. When you click it show new window.
Where needUrl - url your servlet It after run redirect to jsp. It is easy.Code:<INPUT type="button" value="New Window!" onClick="window.open(needUrl,'mywindow','width=400,height=200')">
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?
Code:<INPUT type="button" value="New Window!" onClick="window.open(RequestProcessor,'mywindow','width=400,height=200')">
My Servlet info
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.
Code:<input type="hidden" name="moduleName" value="account">
<input type="hidden" name="trasferType" value="transaction">
I hope the request object will carry this parameters.
You need replace RequestProcessor to "/Module.do".
About parameters you can create function js. which build need url.
for example
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, ...
Sorry for the delayed response.
But the thing is not actually working.
Nothing is getting populated under var moduleName . I also tried getElementByName but not working.Code:var moduleName = document.getElementById("moduleIdEl");
One more error i get after directly constructing the url likeCode:var moduleName = document.getElementByName("moduleName");
needUrl=/Module.do?accountName=account&transferType=transac tion
HTTP Status 405 - HTTP method GET is not supported by this URL
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
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>