display the form values from view page

S

strutsng

register.jsp is the view page, and when the user click submit button,
it will go to result.jsp based on struts-config.xml. The followings
are the code fragment of each significant files.

My question is for result.jsp, I am now using
request.getParameter("name")
to get the name property specified in the form. It is working code,
I just want to ask if this is the best appraoch in struts application?


Please advise. thanks!!


register.jsp
=============
<html:form action="register.do">
<P>Name: <html:text property="name"></html:text>
<P>Address: <html:text property="address"></html:text>
<P>ZIP: <html:text property="zip"></html:text>
<html:submit>Register Online</html:submit>
</html:form>


result.jsp
==========
<H3>Name = <%= request.getParameter("name") %></H3>


struts-config.xml
=================
<action-mappings>
<action name="registerFormBean" path="/register" scope="request"
type="com.insights.struts.actions.RegisterAction" input="register.jsp">
<forward name="success" path="/result.jsp"/>
</action>
</action-mappings>


RegisterAction.java
===================

public ActionForward execute(...)
{
//etc...
forward = mapping.findForward("success");
}
 
R

Ryan Dillon

to get the name property specified in the form. It is working code,
I just want to ask if this is the best appraoch in struts application?

Hi,

Another way of doing it might be to use the <bean:write/> tag:

result.jsp
==========
<H3>Name = <bean:write name="registerFormBean" property="name"/></H3>


An additional benefit of this is that the write tag will HTML encode
the name value before it is output.

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top