[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1029
  • Last Modified:

(servlets)RequestDispatcher.forward == disabling javascript?

hi, this is my code for save data, after the saving, it will use the request depatcher's forward method to return to the origninal page.. but the problem is, the javascript functions are all "disappear"... do anyone here experience the same thing before? plz help!

public class SaveData extends HttpServlet {
   
    /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
       
        String address = "data_entry.jsp";
       
        /*
        haven't write the code for save data yet...
        */

        RequestDispatcher dispatcher =
                request.getRequestDispatcher(address);
        dispatcher.forward(request, response);
    }
   
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
   
    /** Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
   
    /** Returns a short description of the servlet.
     */
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold>
}
0
InNoCenT_Ch1ld
Asked:
InNoCenT_Ch1ld
  • 4
  • 3
  • 3
  • +1
2 Solutions
 
objectsCommented:
what do mean by disappear?
Whats the jsp page look like?
0
 
fargoCommented:
u must be using relative paths in the jsp itself for the external javascript files. When u use redirect the response is forwarded to the new page, and the jsp page loaded couldn't get the relative paths properly.

if u are using struts --> use html:rewrite tag
if u are not using struts --> use request.getContextPath()+path to external js files.
0
 
fargoCommented:
take a look here, the same problem with css for one (like u have with javascript )
http://www.experts-exchange.com/Web/Web_Languages/JSP/Q_21818866.html
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
InNoCenT_Ch1ldAuthor Commented:
in that jsp (data_entry.jsp), i got some javascript such as "no-right-click" and "tabview"..
when the jsp is first loaded, they work perfect..

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="../../../tabpanel_js/tabview.css" />
       
        <script type="text/javascript" src="../../../misc_js/norightclick.js"></script>
        <script type="text/javascript" src="../../../tabpanel_js/tabview.js"></script>
    </head>
    <body>
       <form id="data_entry_form" action="SaveData">
            //the tab here - code too long
            <input type="submit" value="Search">
       </form>

     </body>
</html>
0
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
put forward the content of "data_entry.jsp".
0
 
InNoCenT_Ch1ldAuthor Commented:
fargo, let me try it out first!
sounds promising!
0
 
fargoCommented:
i assue that u have misc_js and tabpanel_js directly accessed with appln. like http://localhost:8080/myapp/misc_js ....

then use
<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/tabpanel_js/tabview.css" />
<script type="text/javascript" src="<%= request.getContextPath() %>/misc_js/norightclick.js"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/tabpanel_js/tabview.js"></script>
0
 
objectsCommented:
try adding a base tag to your jsp to specify the base url
0
 
InNoCenT_Ch1ldAuthor Commented:
i did as fargo mentioned and it work!!

but what is a base tag?
0
 
objectsCommented:
Base tag allows you to specifyt the base url for the page. Saves you specifying it for every relative url on the page, and accidently missing one.

http://www.w3schools.com/tags/tag_base.asp
0
 
InNoCenT_Ch1ldAuthor Commented:
tks for helping! ;-)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now