简体   繁体   中英

edit javascript using jsp

I have a HTML page where I have some images located with a defined size, where the size is coming from a java script. Now I need to create another JSP or HTML where I should be able to set preference for size of the images. The next time when server starts it should take the new size. Meaning the java script should be edited. If this is achievable without using javascript, through jquery or simply using html ,that is also fine. Any help appreciated.

In my opinion the action "set a preference for size of the images" should be executed in the Server side. But javascript, JSP or HTML just serve to Client.

suggest: Please try to use the framework JSF and CDI(Contexts and Dependency Injection). In JSP, you can define the size of images by using the variable, which can be dynamic changed in a java bean.

You can write JavaScript directly to the page generated by the JSP:

<head>
     <script type="text/javascript">
        var imageSzie= '${pageScope["imageSizeSelected"]}';
    </script>
</head>

To do this you would need to include the "image size" to display in the request to the 2nd JSP.

Example:

In the first JSP the user selects an image size (this sets the value of "imageSizeSelected" via JS) then clicks an "OK" button with an href of:

href="/secondPage?imageSize=imageSizeSelected"

In the second JSP you have:

<head>
     <script type="text/javascript">
        var imageSize= '${param.imageSizeSelected}';
    </script>
</head>

imageSize should now be a value you can use in JS to determine image size.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM