开发者

Struts - What changes are needed to add a new JSP?

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" />
      <f开发者_如何学JAVAorward 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.


Nathan told you everything you need to know, I'm just adding an example of how I would write the struts-config file:

 <action path="/signup" 
      name="signupForm" 
      validate="true" 
      input="/signup.jsp"> 
      <forward name="successPC" path="/PC/signupSuccess.jsp" /> 
      <forward name="failurePC" path="/PC/signupFailed.jsp" />
      <forward name="successMobile" path="/mobile/signupSuccess.jsp" />
      <forward name="failureMobile" path="/mobile/signupSuccess.jsp" />
 </action>

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜