Struts - 添加新的 JSP 需要进行哪些更改?
我正在对基于 Struts1 的现有 Web 应用程序进行更改 - 该应用程序已经由各种形式和内容组成。行动。
我想做的是
- 为网站的移动版本添加一些页面。
- 例如,我想添加一个 JSP 页面,其中包含一个带有一些表单的表单 字段(与PC中的字段相同) 版本)带有提交按钮。在 提交,我想调用相同的 处理PC中表单的ACTION类 版本。
这可能吗?请指出任何解释上述内容的链接。
Edit1:
我的 struts-config.xml 动作映射中的几行。
<action path="/signupPC"
name="signupPCForm"
validate="true"
input="/signupFailedPC.jsp">
<forward name="success" path="/signupSuccessPC.jsp" />
<forward name="failure" path="/signupFailedPC.jsp" />
</action>
@内森 如何添加移动设备专用页面 在这里?
我应该添加一个新动作吗 路径=“/signupMobile”在这里? - 这意味着添加 < html:form action="/signupMobile.do" 方法=“帖子”>到我的移动jsp?
我希望我不必添加新的 Form bean 因为我想使用 与基于 PC 的版本相同的 Form.java。
I am making changes to an existing web application based on Struts1 - which already is made up of various forms & actions.
What I am trying to do is
- Add a few pages for the mobile version of website.
- For example, I want to add a JSP page that contains a form with a few
fields (same as that in the PC
version) with a submit button. On
submit, I would like to call the same
ACTION class which handled the form in the PC
version.
Is this possible? Please point me to any links that explain the above.
Edit1:
a few lines from my struts-config.xml action-mappings.
<action path="/signupPC"
name="signupPCForm"
validate="true"
input="/signupFailedPC.jsp">
<forward name="success" path="/signupSuccessPC.jsp" />
<forward name="failure" path="/signupFailedPC.jsp" />
</action>
@Nathan
How do I add mobile specific pages
here?Should I add a new action
path="/signupMobile" here?
- which means adding < html:form action="/signupMobile.do"
method="post" > to my mobile jsp?I hope I don't have to add a new Form bean as I would like to make use of
the same Form.java meant for PC based version.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Nathan 告诉了您需要知道的一切,我只是添加了一个如何编写 struts-config 文件的示例:
您将调用相同的操作(java 类的方法)并根据调用该方法的设备,您将转发至 PC 成功或移动成功网页。
Nathan told you everything you need to know, I'm just adding an example of how I would write the struts-config file:
You will call the same action(method of the java class) and depending on the device who called the method, you will forward to the PC success or the mobile success webpages.
在你的 struts-config 中,你有一组动作映射元素。对于每个 actionMapping,您都有一个或多个前向元素。每个转发将应用程序中的相对 URL 映射到字符串。将特定于移动设备的转发添加到操作映射。 ActionMapping 对于该映射的每个转发都有一个条目,您可以通过在 struts-config 中提供的字符串标识符来查找它们。然后,在您的 Action 中,您需要代码来根据该操作是从 PC url 还是移动 url 调用,从 ActionMapping 中提取正确的 ActionForward。
In your struts-config you have a set of action-mapping elements. For each actionMapping you have one or more forward elements. Each forward maps a relative url in the app to a string. Add a mobile-specific forward to the action mapping. ActionMapping has one entry for each forward for that mapping, you look them up by the string identifier you give it in struts-config. Then in your Action you'll need code to pull the right ActionForward out of the ActionMapping based on whether the action is being called from a PC url or a mobile url.