实习日志(4):Flex向Servlet传值
因为对Flex结合Servlet开发流程不是很熟悉,导致完整的登录模块还没有写出来,不能实现页面跳转(flex没有跳转概念,先这么叫着吧),进度的确偏慢, 不过东西再少也是今天的工作成果嘛,先记录下来吧。。 ? 理论支持:Flex提供了相应的标签Http Service去支持标准的HTTP GET和POST请求,以及对HTTP返回数据的处理。 ? 因此,在开发过程中采用Http Service传值。 创建web工程,附加flex属性,项目的创建跟昨天《初探BlazeDS》的步骤差不多。 登录窗口: 窗口代码: <?xml version="1.0" encoding="utf-8"?> <mx:Application backgroundGradientColors="backgroundColorFareArray" xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:HTTPService id="lg" url="http://localhost:8080/BlackBoardV1.2/UserServlet" useProxy="false" method="post"> <mx:request> <userName>{userName.text}</userName> <password>{password.text}</password> <type>{radiogroup.selectedValue}</type> <flag>{"check"}</flag> </mx:request> </mx:HTTPService> <mx:Script> <![CDATA[ import mx.controls.Alert; public function lgin(event:Event):void{ lg.send(); } ]]> </mx:Script> <mx:Style source="css/back.css"/> <mx:Panel width="349" height="222" layout="absolute" title="登录窗口" fontSize="14"> <mx:Label x="32" y="23" text="帐号:"/> <mx:Label x="32" y="62" text="密码:"/> <mx:TextInput x="82" y="23" id="userName"/> <mx:TextInput x="82" y="64" id="password" displayAsPassword="true"/> <mx:Button x="171" y="131" label="注 册"/> <mx:Button x="82" y="131" label="登 录" click="lgin(event);"/> <mx:Label x="32" y="102" text="权限:"/> <mx:RadioButtonGroup id="radiogroup" labelPlacement="right"/> <mx:RadioButton x="87" y="100" label="普通" value="普通" groupName="radiogroup"/> <mx:RadioButton x="189" y="100" label="高级" value="高级" groupName="radiogroup"/> </mx:Panel> </mx:Application> 创建UserServlet,HttpService的url将其定位。代码如下: public class UserServlet extends HttpServlet { private static final long serialVersionUID = 1L; public UserServlet() { super(); } protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException { // 获得标志位 response.setCharacterEncoding("utf-8"); response.setContentType("text/html"); // 获取标识位,判断下一步操作 String flag = request.getParameter("flag"); System.out.println(flag); /** * 验证用户登陆 */ if (flag.equals("check")) { // 得到用户名和密码,验证用户是否合法 String userName = request.getParameter("userName"); String password = request.getParameter("password"); String type = request.getParameter("type"); //处理中文乱码 userName=NewString.getNewString(userName); password=NewString.getNewString(password); type=NewString.getNewString(type); System.out.println("type"+type); System.out.println(userName); System.out.println(password); // 验证用户 UserDao udao = new UserDao(); if (udao.checkUser(userName,password,type)) { // 用户合法 System.out.println("用户合法"); } else { // 用户不合法 System.out.println("用户不合法"); } } } protected void doPost(HttpServletRequest request,IOException { this.doGet(request,response); } }
后台打印内容: 错误及解决方法: 1、在配置文件中部署Servlet时报错: 2、加载数据库驱动报错: com.microsoft.sqlserver.jdbc.SQLServerConnection <init> ? 虽然在工程的lib包和Tomcat/common/lib包中没有sqljdbc.jar,且加入了sqljdbc4.jar,但依旧报错。 查了好久资料才发现因为之前错误的附加了sqljdbc.jar,虽然在工程的lib包和Tomcat/common/lib包中删除了sqljdbc.jar,但是。。。。 %Tomcat_Home%/webapps/工程名/WEB-INF/lib包中还有sqljdbc.jar!!!一定要将其删除,因为编译器会默认使用sqljdbc.jar。 晕死,找了一下午错误,删除之后终于成功加载数据库。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- c# – 在页面激活长时间运行的任务时写入多个文本
- iphone – 如何访问项目中的本地文件
- iphone – sqlite_step中的EXC_BAD_ACCESS(语句)
- Oracle 12cR1 RAC 在VMware Workstation上安装(下
- ruby-on-rails – 如何在Rails资产管道中确定给定
- NSObject到NSString Objective-C
- c# – 有没有办法在不使用Thread.Sleep的情况下延
- c – 为什么boost :: asio :: io_service不能用s
- ruby-on-rails – AWS S3,缺少需要的Paperclip:
- 前端每周清单第 38 期: Node 9 发布,Kotlin 与