myeclipse 开发struts(四)

 JAVA类建立好了

 记住了forward元素 我们建立页面jsp。页面需要到webroot目录下建立:

首先建立lianxi.jsp

你可能会使用myeclipse来自动生成JSP,那是可以的 但是我建议建好后将里面的所有代码情调:将我下面的代码复制进去

<%@ page language="java" pageEncoding="GB18030"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
 
<html>
 <head>
  <title>JSP for LianxiForm form</title>
 </head>
 <body>
  <html:form action="/LianxiAction.do">
   password : <html:text property="password"/><html:errors property="password"/><br/>
   username : <html:text property="username"/><html:errors property="username"/><br/>
   <html:submit/><html:cancel/>
  </html:form>
 </body>
</html>

 

加粗的代码表明这个JSP要去找的ACTION,这个ACTION要在struts-config.xml配置了,我们现在就去配置

  <action-mappings >
  <action
      attribute="lianxiForm"
      input="/lianxi.jsp"
      name="lianxiForm"
      path="/LianxiAction"
      scope="request"
      type="com.yourcompany.struts.LianxiAction">
      <forward name="success" path="/success.jsp" />
      <forward name="failure" path="/lianxi.jsp" />
    </action>
  </action-mappings >

注意各个参数的配置,都是有讲究的其中 那么参数是上面的form bean的名字,

而path是JSP的那个 *.do的前缀

而TYPE则是 action的相对路径

还有两个forward

其他暂时不重要

 

设置需要跳转的页面 success.jsp

 这个简单,可以自行发挥:看看我的

<%@ page language="java" pageEncoding="GB18030"%>

success

简单吧

好了 完毕!我们将tomcat启动起来吧,由于我的myeclipse和tomcat做了关联,所以我是使用的myeclipse来启动tomcat:

 

启动后:

访问

http://localhost:8080/strus1/   点击lianxi.jsp 在password 属性 输入WWW 点击 submit  如果可以跳转到 success页面就行了...

 

总算是搞定了,无论是应用还是代码都有点简陋。尤其感谢刘铁手的新版struts in action 比较清晰,谢谢!

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值