您的位置:首页 > 编程语言 > Java开发

struts2初探

2016-01-24 11:34 495 查看

初学struts框架几日,以一个小例子记录一下当前理解。 struts2的核心在与一个配置文件,名为struts.xml.此配置文件好比一个控制枢纽,对于所有请求,通过action来管控。 例子: input.jsp给出表单供填写:



代码:

<body>
<form action="product-save.action" method="post">
//这个.action必须在struts.xml里进行配置
ProductName: <input type="text" name="productName"/>
<br><br>
ProductDesc: <input type="text" name="productDesc"/>
<br><br>

ProductPrice: <input type="text" name="productPrice" />
<br><br>

<input type="submit" value="Submit"/>
<br><br>

</form>
</body>


detail.jsp显示表单内容:


代码:

ProductId: productIdProductName:{productId }

ProductName: {productName }

ProductDesc: ${productDesc }
<br><br>

ProductPrice: ${productPrice }
<br><br>


下面是struts.xml:

<struts>
<package name="myvaluestack" extends="struts-default">
<action name="product-save" class="com.atguigu.struts.valuestack.Product"
method="save">//save方法在com.atguigu.struts.valuestack.Product类里
<result name="success">details.jsp</result>success是sava 方法返回的字符串,匹配成功后转发到details页面。
</action>
</package>
</struts>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: