开发者

Invalid JS/CSS resource paths when opening a JSP page through a Struts action class

开发者 https://www.devze.com 2023-03-11 07:41 出处:网络
This is the Struts Action class: public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {

This is the Struts Action class:

public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
    ActionForward forward = null;

    try {
        forward = mapping.findForward(request.getParameter("nextPage"));
        // response.getWriter().print(request.getSession().getServletContext().getRealPath("."));
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        return forward;
    }
}

And here is the JSP as per previously resolved ActionForward instance:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Description</title>
        <script src="/jsp/html5/sencha-touch/sencha-touch.js" type="text/javascript"></script>
        <link href="/jsp/html5/sencha-touch/resources/css/sencha-touch.css" rel="stylesheet" type="text/css" />
        <scri开发者_JAVA技巧pt type="text/javascript" src="/jsp/html5/description.js"></script>
    </head>
    <body>
    </body>
</html>

The paths from this file above have been adjusted so that they are relative to Action class' current working directory. However, nothing gets shown in the browser. Reverting back to original paths (and accessing the JSP file directly, not through the Action class) outputs the desired page in a browser:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Description</title>
        <script src="./sencha-touch/sencha-touch.js" type="text/javascript"></script>
        <link href="./sencha-touch/resources/css/sencha-touch.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="./description.js"></script>
    </head>
    <body>
    </body>
</html>

[-EDITED-] My need is to go through the Action class, so I have got to work around this situation somehow. The included JavaScript / CSS files are not including themselves other files, so I do not know if the problem really is related to the working directory and how.

Any opinions ? Thank you

0

精彩评论

暂无评论...
验证码 换一张
取 消