flex是Macromedia公司新推出的web服务端,跟asp一样,他是编译执行的,但是他们编译出来的东西却大大不一样,flex可以编译成flash输出到前端页面,以实现RIA.
说白了flex是可以用编码的方式来写flash。
jsp是javaweb里用的动态页面语言。jsp中分为静态部分和动态部分,静态部分网页直接解析,动态部分需要经过编译成.class才能解析。
两者不同。
Struts2+Flex开发
首先你可以用XML来实现,这个应该来说比较普遍。
不用XML的话,也可以返回数据给FLEX。但是不用action的跳转
public String execute()throws Exception
{
if(action.checkUser(getName(), getPassword()))
{
response.getWriter().write("success");
}else
{
response.getWriter().write("error");
}
return null;
}
比如在action里,判断用户登录成功返回success给FLEX,失败返回error.
记住最后要返回null,因为不用action的跳转。
Flex里用HTTPService来发出请求,如下:
<mx:HTTPService id="service" url="http://localhost:8080/JavaEEFlex/login" result="serviceRequest(event)" method="POST" >
<mx:request xmlns="">
<name>
{na.text}
</name>
<password>
{password.text}
</password>
</mx:request>
</mx:HTTPService>
然后用FLEX接受数据:
private function serviceRequest(event:ResultEvent):void{
if(event.result.toString()=="success")
{ ExternalInterface.call("function(){window.location.href='http://localhost:8080/JavaEEFlex/Content.html';}");
}
if(event.result.toString()== "error")
{
Alert.show('用户名或密码有误');
}
}
基本就是如上了。来自:求助得到的回答
怎么用java和flex实现增删改查
flex与java实现增删改查
用的是MySQL数据库。
1,建一个userdb库,再建userinfo表,字 段:id(int),username(varchar),password(varchar)。
view plaincopy to clipboardprint?
create database userdb;
use userdb;
create table userinfo(
id int(10) not null auto_increment,
username varchar(20),
password varchar(20),
primary key(id));
2,DBConnection.java
view plaincopy to clipboardprint?
package com.datainfo;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBConnection {
public static Connection getConnection() throws ClassNotFoundException,
SQLException {
Connection conn = null;
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/userdb";
String username = "root";
String password = "mysql";
Class.forName(driver);
conn = DriverManager.getConnection(url, username, password);
return conn;
}
}
3,User.java
view plaincopy to clipboardprint?
package com.datainfo;
public class User {
private int id;
private String username;
private String password;
public User() {
}
/**
* @return the id
*/
public int getId() {
return id;
}
/**
* @param id
* the id to set
*/
public void setId(int id) {
this.id = id;
}
/**
* @return the username
*/
public String getUsername() {
return username;
}
/**
* @param username
* the username to set
*/
public void setUsername(String username) {
this.username = username;
}
/**
* @return the password
*/
public String getPassword() {
return password;
}
/**
* @param password
* the password to set
*/
public void setPassword(String password) {
this.password = password;
}
}
4,UserDAO.java
view plaincopy to clipboardprint?
package com.datainfo;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import com.datainfo.DBConnection;
public class UserDAO {
public ArrayList getUserList() throws ClassNotFoundException, SQLException {
Connection conn = DBConnection.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from userinfo");
ArrayList userList = null;
try {
userList = new ArrayList();
while (rs.next()) {
User user = new User();
user.setId(rs.getInt("id"));
user.setUsername(rs.getString("username"));
user.setPassword(rs.getString("password"));
userList.add(user);
}
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return userList;
}
public void addUser(User user) throws ClassNotFoundException, SQLException {
Connection conn = DBConnection.getConnection();
String sql = "insert into userinfo (username,password) values (?,?)";
try {
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, user.getUsername());
pstmt.setString(2, user.getPassword());
pstmt.executeUpdate();
pstmt.close();
conn.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void updataUser(User user) throws ClassNotFoundException,
SQLException {
Connection conn = DBConnection.getConnection();
String sql = "update userinfo set username=?,password=? where id=?";
try {
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, user.getUsername());
pstmt.setString(2, user.getPassword());
pstmt.setInt(3, user.getId());
pstmt.executeUpdate();
pstmt.close();
conn.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void deleteUser(User user) throws ClassNotFoundException,
SQLException {
Connection conn = DBConnection.getConnection();
String sql = "delete from userinfo where id =?";
try {
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, user.getId());
pstmt.executeUpdate();
pstmt.close();
conn.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
flex4 如何做出弹出窗口 ,并且能在里面填写东西并提交。。
在弹出的windows中 使用回调, 设置主页面的参数时,在使用Object对象:
1. 在父窗口中打开的时候增加owner参数为this:
var childWin:ChildWin = new ChildWin();
childWin.owner = this; // this 即为当前窗口
PopUpManager.addPopUp(childWin, this, false);
2. 在子窗口中调用方式
var pModule:Object = owner;
pModul.回调主页面方法();
// 关闭 pop windows
PopUpManager.removePopUp(this);
方法使用的是 public function 回调主页面方法()
--------------------------------------------------------------------
打开窗口方式二: 居中打开
var childWin : ChildWin = ChildWin(PopUpManager.createPopUp(this, ChildWin, true));
childWin.owner = this;
PopUpManager.centerPopUp(childWin);
--------------------------------------------------------------------
打开窗口方式三: 居中打开
var childWin:ChildWin = new ChildWin();
childWin.owner = this; // this 即为当前窗口
PopUpManager.addPopUp(childWin, this, false);
PopUpManager.centerPopUp(childWin);
这个是我写的
在我的主应用程序中,有一个按钮、datagrod列表(在一个状态下 假如为:State1)。我想:当点击这个按钮时,可以弹出窗口(在State2中),然后在弹出的窗口中输入用户名、密码,提交到State1,并可以在State1的datagrod列表中显示出来。 我能提交到State1中,但是写不到datagrod列表中,这是怎么回事
按照你说的 我很难知道是为什么,按照我的理解写了一个例子你看下和你的区别在哪里就应该知道错在哪里了。
代码:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
initialize="initSet()"
width="100%" height="100%">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.managers.PopUpManager;
[Bindable] private var gridCollection:ArrayCollection;
private function initSet():void {
gridCollection = new ArrayCollection();
popUpBtn.addEventListener(MouseEvent.CLICK, popUpWin);
}
private function popUpWin(mouseEvent:MouseEvent):void {
var childWin:ChildWin = new ChildWin();
childWin.owner = this; // this 即为当前窗口
PopUpManager.addPopUp(childWin, this, false);
PopUpManager.centerPopUp(childWin);
}
public function returnValue(user:String, password:String):void {
trace(" user : " + user);
trace(" password : " + password);
var obj:Object = new Object();
obj.user = user;
obj.password = password;
gridCollection.addItem(obj);
}
]]>
</fx:Script>
<s:VGroup width="100%" height="100%">
<s:Button id="popUpBtn" label="调用弹出窗口"/>
<mx:DataGrid id="dataGrid" dataProvider="{gridCollection}">
<mx:columns>
<mx:DataGridColumn headerText="用户" dataField="user"/>
<mx:DataGridColumn headerText="密码" dataField="password"/>
</mx:columns>
</mx:DataGrid>
</s:VGroup>
</s:Application>
参考资料:http://hi.baidu.com/ye5120127/blog/item/bfa1cf08f4971b2bb1351dec.html
在哪里写Flex 的Button单击事件代码?
步骤如下:
1. button 中注册事件。 click="do_Click();"
2. 在页面中添加<mx:Script>标签,在script标签中写方法,事件。
3. 完整例子如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private function do_Click():void {
Alert.show("haha");
}
]]>
</mx:Script>
<mx:Button id="button" label="click me" click="do_Click();" />
</mx:Application>
flex怎么设置把一个文本框,设置成一个密码框
<mx:TextInput displayAsPassword="true"/>
如果是Text的话 你就必须自己渲染或是重写组件
flex与java到底是怎么结合的 什么是flex 数据绑定java
RemoteObject,flex与java交互多是用这个通讯。效率比httpservice高更多
如果想你说的多数是用RemoteObjcet的话
它的功能不只是可以调用java后台的类的方法吗
但是如果我前台是Flex做的,然后我想要像后台提交表单的话 如果不用httpService不是很麻烦吗?
flex端可以
[Bindable]
[RemoteClass(alias="com.redmoon.rmss.model.post.Post")]
这样把数据和java端的Post绑定(com.redmoon.rmss.model.post.Post是java端的Post类路径)。
在Flex端Post.as中声明[Bindable]
[RemoteClass(alias="com.redmoon.rmss.model.post.Post")]
,两边的数据类型要一至,这样从Java端取得的数据就会自动的和Flex端的对应了),数据在Flex端封装好再传给Java。
可以在网上搜下,有相关的例子的
你是说如果我要向后台上传一个文件
以前的话我再sturts的actionform里面定义一个FileForm类型的属性 浏览文件后 点提交就可以把文件和其他的文本内容一起提交过去(比如:username,password)都是在一个form里的,以前这样是好使的,
那么你的意思是我现在在Flex里面绑定一个同样的actionForm.as里面的属性和后台java的actionForm属性相对应,提交的时候就可以传到后台了吗?
那这个带上传文件的 form要具体怎么提交呢?
转载请注明出处51数据库 » flexpassword jsp和flex的区别
一网情深