Posted By:
Jeya_Selliah
Posted On:
Wednesday, February 20, 2002 08:43 AM
I have a jsp form that calls the AgreementHandler servlet and uses method=POST.This form has 3 buttons view policy, accept agreement, and decline. I am having two problems 1) If I press any of the three button It will only go to the accept agreement or sometimes I won't go to any page just stays in the page. How can I call the page as I hit the buttons. EX: If I hit accept agreemant I goto accept.jsp and If I hit view button I goto view.jsp, etc. 2) I am also trying to implement this: If the user trys to access the a page without hitting the acceptagreement button, the user should redirected to the main page (where the three buttons are). This is not happening with my program. Could you please take a l
More>>
I have a jsp form that calls the AgreementHandler servlet and uses
method=POST.This form has 3 buttons view policy, accept agreement, and decline. I am having two problems
1) If I press any of the three button It will only go to the accept agreement or sometimes I won't go to any page just stays in the page. How can I call the page as I hit the buttons. EX: If I hit accept agreemant I goto accept.jsp and If I hit view button I goto view.jsp, etc.
2) I am also trying to implement this: If the user trys to access the a page without hitting the acceptagreement button, the user should redirected to the main page (where the three buttons are). This is not happening with my program. Could you please take a look
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String scheme = req.getScheme();
String server = req.getServerName();
String port = "";
port += req.getServerPort();
String url = scheme+"://"+server+":"+port+"/acceptagreement.jsp";
String btnAcceptAgreement = req.getParameter("btn_accept_agreement");
String btnViewPolicy = req.getParameter("btn_view_policy");
String btnDeclineAgreement= req.getParameter("btn_decline_agreement");
//out.println("url = " + req.getRequestURI());
//out.println("session = " + req.getSession(true));
HttpSession session = req.getSession(true);
//check whether user hit the accept agreement button
if (buttonPressed(btnAcceptAgreement)) {
//Not a valid hit.
Object agreement = session.getValue("agreement.isChecked");
if (agreement == null){
session.putValue("agreement.target", HttpUtils.getRequestURL(req).toString());
res.sendRedirect(req.getScheme()+"://"+req.getServerName()+":"+
req.getServerPort()+"/agreement.jsp");
return;
}
} else {
//didn't hit the accept agreement button
//accessing the accept agreement page without hitting the accept agreement button
if (!buttonPressed(btnAcceptAgreement) ){
res.sendRedirect(req.getScheme()+"://"+req.getServerName()+":"+
req.getServerPort()+"/agreement.jsp");
} else {
session.putValue("agreement.isChecked", btnAcceptAgreement);
try {
String target = (String)session.getValue("agreement.target");
if (target!= null)
res.sendRedirect(target);
return;
} catch (Exception e) {
//couldn't redirect to the target....redirecting to home page
res.sendRedirect(req.getScheme()+"://"+req.getServerName()+":"+
req.getServerPort()+"/bidschedule.jsp");
}
}
}
//for each button pressed, switching the control to that page
if (buttonPressed(btnAcceptAgreement)) {
res.sendRedirect(req.getScheme()+"://"+req.getServerName()+":"+
req.getServerPort()+"/acceptagreement.jsp");
}
if (buttonPressed(btnViewPolicy)) {
RequestDispatcher rd =
getServletContext().getRequestDispatcher("/viewpolicy.jsp");
rd.include(req, res);
return;
/*res.sendRedirect(req.getScheme()+"://"+req.getServerName()+":"+
req.getServerPort()+"/viewpolicy.jsp");*/
return;
}
if (buttonPressed(btnDeclineAgreement)) {
res.sendRedirect(req.getScheme()+"://"+req.getServerName()+":"+
req.getServerPort()+"/bidschedule.jsp");
}
out.close();
}
<<Less