java spring 页面导入js文件

wenwen1 发布于 2012/10/11 16:30
阅读 1K+
收藏 0

我的jsp文件如下:

<%@page language="java" isELIgnored="false" contentType="text/html; charset=gbk" pageEncoding="gbk"%>
<jsp:directive.include file="/WEB-INF/sitemesh-decorators/include.jsp"/>
<fmt:setBundle basename="bundles.project-resources"/>
<html>
<head>
<title>Edit <fmt:message key="project.title"/></title>
    <script type="text/javascript" src="../../jquery/js/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="../../jquery/js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../jquery/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath() %>/pages/_project/js/projectApplication.js"></script>
</head>
<body>
<div id="contentarea">     
    <div id="lb"><div id="rb"><div id="bb"><div id="blc">
    <div id="brc"><div id="tb"><div id="tlc"><div id="trc">
    <div id="content">

       
<form:form action="${pageContext.request.contextPath}/mysaveProject" method="POST" modelAttribute="project">
   <table cellpadding="0" cellspacing="0" id="viewTable">
       <tbody>
                    <tr>
                        <td class="label" valign="top">
                            <fmt:message key="project.projectname.title"/>:
                        </td>
                        <td>
                            <form:input id="project_projectName" path="projectName" cssStyle="width:300px;" value="a"/>
                            <script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : "project_projectName",widgetType : "dijit.form.ValidationTextBox",widgetAttrs : {promptMessage: "<fmt:message key="project.projectname.help"/>"}})); </script>
                        </td>

                        <td class="label" valign="top">
                            <fmt:message key="project.setupdate.title"/>:
                        </td>
                        <td>
                            <input id="project_createDate" name="createDate" type="text" value="<fmt:formatDate value="${project.createDate.time}" pattern="MM/dd/yyyy h:mm a"/>" style="width:300px;"/>
                            <script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : "project_createDate",widgetType : "dijit.form.ValidationTextBox",widgetAttrs : {promptMessage: "<fmt:message key="navigation.dateTime.title"/>"}})); </script>
                        </td>
                    </tr>
                    <tr>
                         <td class="label" valign="top">
                           <fmt:message key="projectartical.source.title"/>:
                         </td>
                         <td>   
                           <!-- 下拉框选择 -->                       
                            <form:select path="projectArtical.Source.id" id="projectArtical_source_id" cssStyle="width:300px;" items="${sources}"/>
                           <!-- 下拉框选择 -->       
                         </td>

                        <td class="label" valign="top">
                            <fmt:message key="project.projectno.title"/>:
                        </td>
                        <td>
                            <form:input id="project_projectNo" path="projectNo" cssStyle="width:300px;" value="c"/>
                            <script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : "project_projectNo",widgetType : "dijit.form.ValidationTextBox",widgetAttrs : {promptMessage: "<fmt:message key="project.projectno.help"/>"}})); </script>
                        </td>
                    </tr>
                    <tr>
                        <td class="label" valign="top">
                         <fmt:message key="userinfo.userId.title"/>:
                        </td>
                       <td>
                       <form:input id="userinfo_userId" path="projectNo" cssStyle="width:300px;"/>
                       <script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : "userinfo_userId",widgetType : "dijit.form.ValidationTextBox",widgetAttrs : {promptMessage: "<fmt:message key="userinfo.userId.help"/>"}})); </script>
                       </td>
                       <td class="label" valign="top">
                       <fmt:message key="userbycreater.title"/>:
                       </td>
                       <td>   
                      <!-- 下拉框选择 -->                       
                      <form:select path="userByCreater.id" id="userByCreater" cssStyle="width:300px;" items="${users}"/>                           
                      <!-- 下拉框选择 -->       
                      </td>   
                   </tr>   
                    <tr>
                        <td class="label" valign="top">
                            <fmt:message key="projectartical.attribute"/>:
                        </td>
                        <td>   
                        <!-- 下拉框选择 -->                       
                               <form:select path="projectArtical.CProjectAttribute.id" id="projectArtical_attribute_id" cssStyle="width:300px;" items="${attributes}"/>
                        <!-- 下拉框选择 -->       
                        </td>   
                        <td class="label" valign="top">
                         <fmt:message key="projectartical.type.title"/>:
                       </td>
                       <td>   
                        <!-- 下拉框选择 -->                       
                       <form:select path="projectArtical.CActivityType.id" id="projectArtical_type_id" cssStyle="width:300px;" items="${types}"/>
                       <!-- 下拉框选择 -->       
                     </td>       
                    </tr>   
                    <tr>
                <td class="label" valign="top">
                  <fmt:message key="projectschedule.begindate.title"/>:
                </td>
                <td>
                <input id="projectSchedule_beginDate" name="beginDate" type="text" value="<fmt:formatDate value="${projectSchedule.beginDate}" pattern="MM/dd/yyyy"/>" style="width:300px;"/>
                <script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : "projectSchedule_beginDate",widgetType : "dijit.form.ValidationTextBox",widgetAttrs : {promptMessage: "<fmt:message key="projectschedule.begindate.help"/>"}})); </script>
                </td>
                <td class="label" valign="top">
                <fmt:message key="projectschedule.planenddate.title"/>:
                </td>
                <td>
                <input id="projectSchedule_planEndDate" name="planEndDate" type="text" value="<fmt:formatDate value="${projectSchedule.planEndDate}" pattern="MM/dd/yyyy"/>" style="width:300px;"/>
                <script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : "projectSchedule_planEndDate",widgetType : "dijit.form.ValidationTextBox",widgetAttrs : {promptMessage: "<fmt:message key="projectschedule.planenddate.help"/>"}})); </script>
                 </td>
               </tr>
               <tr>
                <td class="label" valign="top">
                  <fmt:message key="projectartical.level.title"/>:
                </td>
                <td>   
                 <!-- 下拉框选择 -->                       
                  <form:select path="projectArtical.CProjectLevel.id" id="projectArtical_level_id" cssStyle="width:300px;" items="${levels}"/>
                <!-- 下拉框选择 -->       
                </td>   
               <td class="label" valign="top">
                  <fmt:message key="projectartical.projectbudget.title"/>:
                </td>
                <td>
                 <form:input id="projectArtical_projectBudget" path="projectArtical.projectBudget" cssStyle="width:300px;"/>
                 <script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : "projectArtical_projectBudget",widgetType : "dijit.form.ValidationTextBox",widgetAttrs : {promptMessage: "<fmt:message key="projectartical.projectbudget.help"/>"}})); </script>
                </td>
               </tr>
               <tr>
               <td class="label" valign="top">
                 <fmt:message key="projectartical.registdate.title"/>:
               </td>
               <td>
                <input id="projectArtical_registDate" name="registDate" type="text" value="<fmt:formatDate value="${projectArtical.registDate}" pattern="MM/dd/yyyy"/>" style="width:300px;"/>
                <script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : "projectArtical_registDate",widgetType : "dijit.form.ValidationTextBox",widgetAttrs : {promptMessage: "<fmt:message key="projectartical.registdate.help"/>"}})); </script>
               </td>
               <td class="label" valign="top">
                 <fmt:message key="projectartical.extname.title"/>:
               </td>
               <td>
                 <form:input id="projectArtical_extName" path="projectArtical.extName" cssStyle="width:300px;"/>
                 <script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : "projectArtical_extName",widgetType : "dijit.form.ValidationTextBox",widgetAttrs : {promptMessage: "<fmt:message key="projectartical.extname.help"/>"}})); </script>
                </td>
               </tr>
               <tr>
                 <td class="label" valign="top">
                    <fmt:message key="project.specification.title"/>:
                </td>
                <td colspan="3">
                  <form:textarea id="project_specification" path="specification"  cssStyle="width:100%;"/>
                </td>
               </tr>   
                </tbody>
            </table>
            <span class="inputbutton"><input class="savebutton" id="save" type="submit" value="<fmt:message key="navigation.save"/>"/></span>
            <script type="text/javascript">Spring.addDecoration(new Spring.ValidateAllDecoration({elementId:'save', event:'onclick'}));</script>
        </form:form>
        <div class="clear">&nbsp;</div>
    </div>
    </div></div></div></div>
    </div></div></div></div>
</div>
</body>
</html>

而我的projectApplication.js如下:

$(function(){
    $("#projectArtical_attribute_id").change(function (){
        var pro = document.getElementById('projectArtical_attribute_id');
         if(pro.value=="横向"){
             $("#projectArtical_level_id").attr("disabled",true);
             $("#projectArtical_source_id").attr("disabled",false);
             $("#projectArtical_extName").attr("disabled",false);
        }
         if(pro.value=="纵向"){
             $("#projectArtical_level_id").attr("disabled",false);
             $("#projectArtical_source_id").attr("disabled",true);
             $("#projectArtical_extName").attr("disabled",false);
         } 
         if(pro.value=="中心立项"){
             $("#projectArtical_level_id").attr("disabled",true);
             $("#projectArtical_source_id").attr("disabled",true);
             $("#projectArtical_extName").attr("disabled",true);
         }
      });
})

我的js文件放在如图下的路径:

那么jsp中的红色代码应该怎么写啊?

加载中
0
幸福的旁边
幸福的旁边

JS不能引入WEB-INF目录下的东西

但凡能引用的都必须是浏览器能直接打开的

0
0
hzajie
hzajie
在spring中JS能引入WEB-INF目录下的东西,关键是看你视图如何解析.
0
刘甘露
刘甘露

这个我知道有一种操作方法

首先WEB-INF是不能被访问的,但是可以被简接访问

就是我们可以写一个Servlet,通过转差数给这个Servlet通过它读取WEB-INF里的东东

再返回来给页面就行啦

刘甘露
刘甘露
回复 @java_cmm : 是的呢,所以没有多少人放WEB-INF里面,这个就看楼主怎要选择了
Ken5233
Ken5233
通过访问方式是可以做到,但没必要。一个js文件不需要访问权限控制,大可以放到根路径指定目录下
0
Cavalier
Cavalier
你确定这个js非常重要,必须外界不可见?
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部