如何使用angularjs在Struts 1.x的 [英] How to use angularjs with struts 1.x

查看:243
本文介绍了如何使用angularjs在Struts 1.x的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来angularjs和客户端的东西,我加入一个新的页面,使用1.3支柱为框架的旧应用程序。我想用angularjs的前端。

I'm new to angularjs and client side stuff and I'm adding a new page to an old application that uses struts 1.3 as its framework. I would like to use angularjs for the front end.

我知道如何从动作类通过写JSON的前端和向前的动作返回null返回JSON。不过,我不清楚我怎么会在获取之后,控制器内填充变量的作用域。如果我在控制器使用get并获得JSON回来,怎么我的ActionForm的融入这一切?它是有用的呢?我能有一个GET和POST为同一控制器,如果我要发新值回我的行动?而且,我能有这样的变量:$ scope.items = {}
$ scope.items.name =
$ scope.items.email =
然后只需发送json.stringify(项目)作为我的数据在后,如果我不能用表格不知何故?谢谢你的时间。我还没有发现使用具有支柱angularjs多的信息1.3为止。

I know how to return json from the action class by writing the json to the front end and returning null for the action forward. However, I'm unclear how I would populate the scope variables within the controller after the get. If I use a get in the controller and get json back, how does my actionform fit into all this? Is it useful at all? Can I have a get and post for the same controller if I want to send new values back to my action? And, can I have variables like: $scope.items={} $scope.items.name="" $scope.items.email="" And then just send json.stringify (items) as my data in the post if I can't use the form somehow? Thanks for your time. I haven't found much information using angularjs with struts 1.3 so far.

答:我会尽力回答尽可能地我来了什么结论来,但我的问题上面都非常模糊,因为我真的不知道我在谈论我与位置我工作已经结束,公司让我不再访问该code。我的意思早先问了我怎么用行动形式,我通常使用Struts动作和我应该如何去后期间获得从前端到我的动作类的数据呢?我发现,我通常的动感形式是无用的,我想做的事,所以我摆脱它,这会在前端进行修改,当我做了后回传给另一个动作的获取过程中写了一个JSON对象。这像一个正常的岗位做'whateverAction.do',但我不得不配置,我在后发送数据,并将其命名它的东西。然后,我用的request.getParameter(jsonObjName),拿起修改JSON对象,并将其解析到不同的LinkedHashMap对象在JSON对象中的每个对象。我想你可以使用的JSONObject类,而不是LinkedHashMap中,如果您使用的JavaEE,但我是用SE所以我没有访问那些在这个项目中来解析。在这里,另一页我用了后配置的链接:

Answer: I'll try to answer as best as possible what conclusion I came to but my questions above were very vague since I didn't really know what I was talking about and my position with the company I worked for has ended so I no longer have access to that code. What I meant to ask earlier was what am I going to do with the action form that I usually use for struts actions and how am I going to get data from the front end to my action class during a post? I found out that my usual action form was useless for what I wanted to do so I got rid of it and wrote a json object during the get that would be modified on the front end and passed back to another action when I did the post. This is done like a normal post to 'whateverAction.do' but I had to configure the data I was sending in the post and name it something. I then picked up the modified json object by using request.getParameter("jsonObjName") and parsed it to different LinkedHashMap objects for each object in the json object. I think you can use the JSONObject classes instead of LinkedHashMap to parse if you are using JavaEE but I was using SE so I didn't have access to those in this project. Here a link to another page I used for the post configurations:

<一个href=\"http://stackoverflow.com/questions/22881922/how-to-get-the-data-in-struts-from-angularjs-post\">How从AngularJS得到Struts的资料寄给

推荐答案

在Java方面你也可以尝试使用GSON库,使您解析字符串和JSON,但struts1中一般不会有angularjs合身如果您删除在Java端的形式,不是没有意义,保持struts1中。如果没有可能删除struts1中,不仅仅是保持struts1的现有功能,并开始使用struts2的用于何处angularjs应用新屏幕。这将是很容易从事业角度职位的JSON将自动绑定到具有匹配JSON格式properies和名字的bean对象。

On the java side you can also try to use Gson library that allows you to parse string to and from json, but struts1 generally won't fit well with angularjs, if you remove the form on java side, than makes no sense to keep struts1. And if no possibility to remove struts1, than just keep struts1 for existing functionality and start using struts2 for new screens where angularjs is applied. It will be much easier cause the json from angular post will automatically be bound to the bean object that has to match to json properies format and name.

这篇关于如何使用angularjs在Struts 1.x的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆