WebDypro两个页面之间传值
WebDynpro for ABAP TM
Scenario: To create and run a simple WebDynpro Application. We would accept an input value from the user on first screen and display the value entered on the second screen.
Note:Please refer to the SAP? help for detailed information of the components used in this document.
Procedure:
1.Go to transaction SE80. Please note that there is no separate
transaction for creation of WebDynpro application other than SE80.
2.Select “WebDynpro Comp./Intf” from t he list (as shown below)
3.Create a new WebDynpro component by the name ZSAPTECHNICAL_DEMO.
Assign it to the local object.
4.Right click on the WebDynpro component “ZSAPTECHNICAL_DEMO” and
create a view.
Save the application
5.Double-click on the COMPONENTCONTROLLER.
6.Check if the application is in change mode.
7.Create a node as shown below:
8.Create an attribute for the node as shown below:
Save the application.
9.Double-click on the view, FIRST_VIEW, created earlier.
In this step, we would be designing the first screen of our application with the following elements:
?Label for the input field
?Input field
?Button (for Submit)
Drag and drop the element “Label” onto the layout.
After dragging and dropping onto the layout, change the text of the “Label” to “Username” in the right side bottom of the window.
Now drag and drop the “input field” onto the layout.
Now click on the Label element created earlier and set the property of “LabelFor” to “INPUT_FIELD”.
Finally, drag and drop the element “Button” on to the layout.
In the properties window of the Button, do the following:
Change the text to “Submit”
Click on “Create” for the property “OnAction”.
Enter the Action and the Outbound Plug name.
Press “OK” for the creation prompt of Outbound Plug.
Click on “Context”tab. Drag and drop the Node on the right side to the context on the left side.
Click on ‘YES’ for the prompt for the node to copied and mapped.
Save the application.
Click on Layout tab now.
Double-cl ick on the “Input_field” and in the properties:
a)For the property “Value”, select the attribute “Name” by
clicking on the binding button.
We are done with designing of the first screen.
10.In this step, we would design the second screen of our application.
Right-Click on the WebDynpro component and create another view, SECOND_VIEW.
Create a label, “Entered Name” as mentioned in the earlier step.
We would display the value entered on the first screen in an element called “text view”.
Drag and drop the element “Text View” onto the layout.
Click on “Context” tab and map the nodes as in our earlier step.
Go to Tab “Inbound Plugs” and create an inbound plug as shown below:
Go back to the layout now.
Now double-click on the element “TextView” to open the properti es. For the property “Text”, click on the binding button and select “Name”
11. In this step, we would embed the above created views in the window
created in the first step.
a)Double-click on the window “MAIN_WINDOW”.
b)Right-click on the window name and select “EMBED VIEW”.
c)Embed both the views created earlier. Do not select the view
“EMPTYVIEW” which is created by default.
d)Expand the tree.
e)Now right-click on “SUBMIT” and select “Create Navigation”.
f)Select “SECOND_VIEW” for the des t.view.
g)Now select the FIRST_VIEW and make it as default.
Save and activate the application (When activating, select all the six components related to this webdynpro application. If all six components are activated, only then your application executes)
Now your application is ready to execute. Lets look at the method of testing this application.
Testing your WebDynpro Component
1.Right-click on the WebDynpro Component and create WebDynpro
Application.
2.Without changing any values, press SAVE.
3.Execute your WebDynpro application.
一.使用QueryString 使用QueryString在页面间传递值是一种非常常见的方法,我们在ASP中就常常用到。 (1)优点和缺点优点: 优点:1.使用简单,对于安全性要求不高时传递数字或是文本值非常有效。 缺点:1.缺乏安全性,由于它的值暴露在浏览器的URL地址中的。 2.不能传递对象。 (2)使用方法 1.在源页面的代码中用需要传递的名称和值构造URL地址。 2.在源页面的代码用Response.Redirect(URL);重定向到上面的 URL地址中。 3.在目的页面的代码使用Request.QueryString["name"];取出 URL地址中传递的值。 (3)应用举例 1.源页面*.aspx的代码: private void Button1_Click(object sender, System.EventArgs e) { String urlAddress; string Name1; string Name2; string Name3; string Name1Value = "HelloName1"; int Name2Value = 1234567; string Name3Value = "你好名称3"; urlAddress="destinationWebForm.aspx?Name1=" + Name1Value + "&" + "Name2=" + Name2Value.ToString() + "&" + "Name3=" + Name3Value; Response.Redirect(urlAddress); } 2.目的页面destinationWebForm.aspx的代码: private void Page_Load(object sender, System.EventArgs e) { String myName1Value; int myName2Value; string myName3Value; myName1Value = Request.QueryString["Name1"]; myName2Value=Convert.ToInt32(Request.QueryString["Name 2"]); myName3Value = Request.QueryString["Name3"]; } (4)可能出现的问题1在处理Resonse.QueryString函数汉字参数传递时,发生不能完整传递参数的具体值的错误,解决有两个方法。
1。使用QueryString 使用QuerySting在页面间传递值已经是一种很老的机制了,这种方法的主要优点是实现起来非常简单,然而它的缺点是传递的值是会显示在浏览器的地址栏上的(不安全),同时又不能传递对象,但是在传递的值少而安全性要求不高的情况下,这个方法还是一个不错的方案。使用这种方法的步骤如下: 1,使用控件创建web表单(form) 2,创建可以返回表单的按钮和链接按钮 3,在按钮或链接按钮的单击事件里创建一个保存URL的字符变量 4,在保存的URL里添加QueryString参数 5,使用Response.Redirect重定向到上面保存的URL 下面的代码片断演示了如何实现这个方法: 源页面WebForm1.aspx.cs中的部分代码: private void Button1_Click(object sender, System.EventArgs e) { string url; url="WebForm2.aspx?name=" + TextBox1.Text + "&email=" + TextBox2.Text; Response.Redirect(url); } 目标页面WebForm2.aspx.cs中的部分代码: private void Page_Load(object sender, System.EventArgs e) { Label1.Text=Request.QueryString["name"]; Label2.Text=Request.QueryString["email"]; } 2。使用Session变量 使用Session变量是可以在页面间传递值的的另一种方式,在本例中我们把控件中的值存在Session变量中,然后在另一个页面中使用它,以不同页面间实现值传递的目的。但是,需要注意的是在Session变量存储过多的数据会消耗比较多的服务器资源,在使用session时应该慎重,当然了,我们也应该使用一些清理动作来去除一些不需要的session来降低资源的无谓消耗。使用Session变量传递值的一般步骤如下: 1,在页面里添加必要的控件 2,创建可以返回表单的按钮和链接按钮 3,在按钮或链接按钮的单击事件里,把控件的值添加到session变量里 4,使用Response.Redirect(或Server.Transfer)方法重定向到另一个页面5,在另一个页面提取session的值,在确定不需要使用该session时,要显式清除它 下面的代码片断演示了如何实现这个方法: 源页面WebForm1.aspx.cs中的部分代码: private void Button1_Click(object sender, System.EventArgs e) {
https://www.doczj.com/doc/4f12524432.html,页面之间传递值的几种方式 页面传值是学习https://www.doczj.com/doc/4f12524432.html,初期都会面临的一个问题,总的来说有页面传值、存储对象传值、ajax、类、model、表单等。但是一般来说,常用的较简单有QueryString,Session,Cookies,Application,Server.Transfer。 一、QueryString QueryString是一种非常简单的传值方式,他可以将传送的值显示在浏览器的地址栏中。如果是传递一个或多个安全性要求不高或是结构简单的数值时,可以使用这个方法。但是对于传递数组或对象的话,就不能用这个方法了。 这种方法的优点:1.使用简单,对于安全性要求不高时传递数字或是文本值非常有效。 这种方法的缺点:1.缺乏安全性,由于它的值暴露在浏览器的URL地址中的。 2.不能传递对象。 使用方法:1.在源页面的代码中用需要传递的名称和值构造URL地址。 2.在源页面的代码用Response.Redirect(URL);重定向到上面的URL地址中。 3.在目的页面的代码使用Request.QueryString["name"];取出URL地址中传递的值。 例子:(1)a.aspx private void Button1_Click(object sender, System.EventArgs e) { string s_url; s_url = "b.aspx?name=" + Label1.Text; Response.Redirect(s_url); } (2)b.aspx private void Page_Load(object sender, EventArgs e) { Label2.Text = Request.QueryString["name"]; } 二、Session 想必这个肯定是大家使用中最常见的用法了,其操作与Application类似,作用于用户个人,所以,过量的存储会导致服务器内存资源的耗尽。 优点:1.使用简单,不仅能传递简单数据类型,还能传递对象。 2.数据量大小是不限制的。 缺点:1.在Session变量存储大量的数据会消耗较多的服务器资源。 2.容易丢失。 使用方法:1.在源页面的代码中创建你需要传递的名称和值构造Session变 量:Session["Name"]="Value(Or Object)"; 2.在目的页面的代码使用Session变量取出传递的值。Result = Session["Nmae"]
几种JSP页面传值方式八 2010-01-25 几种JSP页面传值方式: 文章分类:Web前端 几种JSP页面传值方式: 1. 隐藏域传值: <form method="post" action="client_crud.jsp" > <input type="hidden" name="id" value="<%=id %>"> 2. URL传值: 用button a. <input name="btnModify" type="button" class="button1" onClick="self.location='client_modify.jsp?id=<%=id %>'" value="修改分销商" /> b.把input的onClick=”modifyRegion()” function modifyRegion() { window.self.location = client_node_modify.jsp?id=<%=id%>"; } 3. JS方式传值 //取得form对象提交表单 with(document.getElementById("userForm")) { method="post"; action="user_add.jsp?command=add"; submit(); } function searchItem() { with(document.forms[0]) { action="servlet/basedata/SearchItemServlet"; method="post"; submit(); } } ---------------------------------------------------------------------------------------------------------------------------------------
这几天做了一个项目,大量用到了JSP与servlet之间的传值,总结了一下 JSP与servlet之间的传值有两种情况:JSP -> servlet, servlet -> JSP. 通过对象request和session (不考虑application)完成传值. 一、JSP -> servlet JSP页面有3种方法向servlet传值:form表单、URL 、其他 ... <%...... session.setAttribute("testSession","Hello session"); reqeust.setAttribute("testRequest","Hello request"); %> click me
... 1、对于该JSP页面form表单的内容,如标签,在servlet可用request.getParameter("username");获取. 2、URL:比如这里的标签的href属性与