js and jsp interaction

2011-09-22  来源:本站原创  分类:Internet  人气:156 

js and jsp interaction 2010-03-04 22:36:36 | Category: Personal Diary | Tags: | font size medium and small subscription.

For the WEB program, the front end (JavaScript) and back-end (JSP / Servlet) is unable to share data, only the back-end program (JSP) to output data to generate pages to the front, this time the page generated JavaScript code may only be called jsp data. Similarly, only the JavaScript inside JSP code in the data submitted to the backend, JSP JavaScript program to get the data.

Then how to use JavaScript in the page data in jsp using jsp page or in the JavaScript data?

First, the JavaScript in the page data jsp how to submit to background procedures can ① JavaScript data to xxx.JSP? Var1 = aaa & var2 = bbb in the form of a URL parameter to the JSP program, now used in jsp
<% String strVar1 = request.getParameter ("var1 ");%> JavaScript script can get to pass over the data;

② by using JavaScript to add a hidden field in the form of information, then submit the form the way the data is passed to the JSP program.

Second, the data page, the JavaScript JSP how to use background data from this relatively simple procedure, using scripts directly in JavaScript <% = strVar1%> jsp program can put the data passed to the JavaScript script to use.

Third, the reference to the following examples:

1, test.jsp

<% @ Page contentType = "text / html; charset = gb2312"%>

String s1 = "Hello";
String s2 = "World!!";

<script language="JavaScript">
<! -
/************************************************* **************
* JavaScript script, placed anywhere in the page can
* Insertclick () function to get the JSP page is passed to the variable s1,
* JavaScript can then modify the value of this variable, then by
* Post to be submitted to the JSP program to use.
************************************************** *************/
function insertclick () {
var1 ="<%= s1%> ";
document.forms ["insertForm"]. mc.value = var1 + document.forms ["insertForm"]. mc.value;
document.insertForm.submit ();
</ Script>

<! - Html page form form, placed in a position not limited to html page ->
<form name="insertForm" method="post" action="get.jsp">
<! - This one is for the following JSP program to pass over the variable value ->
<Input type = "hidden" name = "mc" value ="<%= s2%> ">
<input type="button" value=" Submit ">
</ Form>

2, get.jsp

String strVar1 = request.getParameter ("mc");
out.print (strVar1);

  • js and jsp interaction 2011-09-22

    js and jsp interaction 2010-03-04 22:36:36 | Category: Personal Diary | Tags: | font size medium and small subscription. For the WEB program, the front end (JavaScript) and back-end (JSP / Servlet) is unable to share data, only the back-end program (

  • js call jsp variable 2010-09-08

    Jsp variable in the js call, in the most outside the single quotation mark var js variable = '<% = jsp variable%>'; For example: In the jsp page in <% String str="123"; %> In the JavaScript in function getStr() { var str_tmp = '<%

  • 消除js以及jsp文件中的警告方法 2014-05-24

    下载jQuery下来以后,将它导入到workbench中去,就会有很多黄色的警告(感叹号)出现,下面为大家介绍如何解决这个问题 不知道大家有没有和我一样的经历,就是下载jQuery下来以后,将它导入到workbench中去,就会有很多黄色的警告(感叹号)出现,如果一个个去纠正,那将会很蛋疼~ 博主是一个追求完美的人,所以不希望看到这些令人蛋疼的警告,下面给大家分享博主的解决方案: 博主用的是myEclipse2013,所以路径为 Project-->Properties-->MyEclipse

  • js引用jsp变量和table的列属性问题(很杂) 2012-02-13

    前两个星期在弄一个简单的登录系统,下面是一些小问题,记录在案! 今天遇到一个问题,在测试我写的js逻辑的时候,死活报错,我在我逻辑开始的时候写上一句alert("hello"),也不起作用,总是爆出下面的逻辑某处有错,后来发现,在下面的逻辑中,我使用到了jsp的变量,但是这个jsp的变量是空的,于是转换成js的时候就完全变成一个空白,注意是空白不是空格,比如我这样写var u=<%=name%>;,如果这个name为空的话,这一句就会被解析成:var u=;,而不是var

  • Flex and background (JSP) interaction 2010-06-07

    FLEX in my blog ( www.wolfdream.cn ) use of the FLEX and JAVA interaction, including the following interaction. Previous interaction with FLEX and JAVA are generally used remoteObject JAVA to call back the appropriate way for those relatively small a

  • js and jsp variable in java code access solution for each variable 2010-07-29

    1. js variable for java jsp page code variable. Methods: var JS variable name = <% = JAVA variable name%> 2. java code for js variable. Description: In the JSP in; Java part is executed on the server; js part of the client's browser implementation;

  • js获取jsp中的变量 2013-05-01

    最近一直在为这个问题揪心,目前找到的答案只有: var1 = "<%=varMC%>"; //获取JSP中的变量值 目前又有一个思路,也许可以用js直接获取后台传过来的代码 js数组赋值

  • 使Eclipse下支持编写HTML/JS/CSS/JSP页面的自动提示. 2014-07-05

    我们平时用eclipse开发jsp页面时智能提示效果不太理想,今天用了两个小时发现了eclipse也可以像Visual Studio 2008那样完全智能提示HTML/JS/CSS代码,使用eclipse自带的插件,无需另外安装插件,具体步骤如下 1.打开eclipse→Windows→Preferences→Java→Editor→Content Assist 修改Auto Activation triggers for java的值为:zjava 点击apply按钮 如图: 2.继续打开Ja

  • js向jsp传中文出现乱码的解决方法 2014-07-30

    不管你是在js中用encodeURIComponent还是encodeURI对所要传递的内容转码两次就可以了,然后在jsp中java.net.URLDecoder.decode进行解码,中文即可显示正确. js var username = "我是中文"; encodeURIComponent(encodeURIComponent(username); 或者 var username = "我是中文"; var url = "http://localhos

  • js and jsp pages to obtain access to the source and its application 2010-03-29

    Sometimes we want to know before an address of this page (this page is a link where visitors come's) time, just use the "Access source" approach. javascript for any extension of the pages, but need to talk with other languages (such as JSP, PHP)

  • Business, not part-time (67) --- an outsider to learn java, js, jsp difference 2011-09-09

    Day before the day has continued to deal with emergencies. In fact, very few now living under the sun is the real manual labor to deal with things, that is, the process of dealing with people, constantly on the phone and speak different people, commu

  • js jsp page called Jsp variable 2010-10-09

    javascipt call jsp variables: <% String tbname = "bd_bank"; out.write ("<SCRIPT language="+"'"+"JavaScript"+"'"+"> var tbname ="+"'"+ tbname +"'"+";</ SCRIPT&

  • JS Ajax POST + Chinese parameters to JSP, jsp parsing the parameter is garbled? Acute 2011-01-05

    Customize the environment in the jira three getUsers.jsp, getRoles.jsp, getGroups.jsp file and a jira_tree.js file. The purpose of display in jira a tree, such as Department of the Hong Kong Computer ---- XX [top roles] Head --------- PC [group] ----

  • How to use the js code or Java code jsp tag 2011-05-05

    JSP tag is still very convenient, such as Struts, Spring and other JSP tags provided to us, you can use them to get some variable or calculation. For example struts2 of <s:url value="/admin/unmi.action"/> automatically for us in front of t

  • JSP与JS交互问题 值传递 2014-11-23

    JSP与JS交互问题 值传递 一.在JSP中访问JS返回的值: 问题: <script language="javascript"> <!-- var str="123"; <% String aa; %> --> </script> 怎么让这个JSP里的aa获得JAVASCRIPT中str的值???? 详细一点就是: 复制代码 代码如下: <script language="javascript&qu

  • java jsp jquery json two linkage Menu 2010-03-29

    jsp page: <% @ Page contentType = "text / html; charset = utf-8"%> <% @ Page import = "java.util .*, com.union.dao.Sys_adcontent"%> <% @ Include file = "/ jsp / common / jsphead.jsp"%> <% String basePath

  • Prototype.js and spring of ajax based pagination 2010-05-26

    This is based on prototype.js for ajax page, use the spring framework, custom page label each page into the list, the list into session, only the session page list of stored pages, do not go query the database, the performance will be higher First, c

  • jsp several methods of embedding Flash 2010-11-11

    1. First, the traditional methods. 2. <Object classid = "clsid: d27cdb6e-ae6d-11cf-96b8-444553540000" 3. Codebase = "http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab # version = 7,0,0,0" 4. Width = "550&quo

  • JS reported that the page error "Class not registered" solutions 2011-01-05

    Today, customers received reflects a problem: JS reported that the page error "Class not registered", leading to some JS function JSP page is not available or erroneous execution. Online search for a search of people met this thing Tingduo, but

  • jsp页面中的代码执行加载顺序介绍 2015-03-02

    本篇文章主要是对jsp页面中的代码执行加载顺序进行了详细的介绍,需要的朋友可以过来参考下,希望对大家有所帮助 1. java是在服务器端运行的代码,jsp在服务器的servlet里运行,而javascript和html都是在浏览器端运行的代码.所以加载执行顺序是是java>jsp>js. 2. js在jsp中的加载顺序 页面上的js代码时html代码的一部分,所以页面加载的时候是由上而下加载.所以js加载的顺序也就是页面中<script>标签出现的顺序.<script>