Eclipse开发struts完全指南(3)

2008-02-23 07:54:43来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

注意这里是直接用ActionForward转向的,你也可以按照struts中提供的空白例程struts-blank.war中的做法进行转向,可以比较一下会有收获的。

7、创建登录成功页面

同创建index.jsp页面相同,我们创建welcome.jsp页面,均使用默认设置。并编辑其内容如下:

<%@page pageEncoding="GBK" 

contentType="text/html; 

charset=GBK" %>

<html> 

<head> 

<meta http-equiv="Content-Type" 

content="text/html;

charset=GBK"/> 

<title></title> 

</head> 

<body> 

<% 

String type = request.getParameter("type"); 

if(type!=null&&type.equals("true")){ 

out.print("欢迎您的光临!"); 



} 

else{ 

out.print("对不起,你输入的用户名或者密码错误!"); 

} 

%> 

</body> 

</html>

8、增加Struts-config.xml中的配置

添加formbean的配置,在标签之间加入:

<form-bean 

name="loginForm" 

type="com.is.form.LoginForm"/>

添加jsp文件的映射,在和标签之间加入:

<action 

path="/index" 

forward="/index.jsp"/> 

<action 

path="/welcome" 

forward="/welcome.jsp"/>

添加action文件的映射,在和标签之间加入:

path="/logincheck" 

type="com.is.action.LoginAction" 

name="loginForm" 

scope="request" 

validate="true"/>

修改后的struts-config.xml大致如下形式:

<?xml version="1.0"?> 

<!DOCTYPE struts-config PUBLIC "-

//Apache Software Foundation

//DTD Struts Configuration 1.2//EN"

"http://struts.apache.org/dtds

/struts-config_1_2.dtd"> 

<struts-config> 

<data-sources> 

</data-sources> 

<form-beans> 

<form-bean 

name="loginForm" 

type="com.is.form.LoginForm"/> 

</form-beans> 

<global-exceptions> 

</global-exceptions> 

<global-forwards> 

</global-forwards> 

<action-mappings> 

<action 

path="/index" 

forward="/index.jsp"/> 

<action 

path="/welcome" 

forward="/welcome.jsp"/>    

<action 

path="/logincheck" 

type="com.is.action.LoginAction" 

name="loginForm" 

scope="request" 

validate="true"/> 

</action-mappings> 

 <controller processorClass=

 "org.apache.struts.tiles.TilesRequestProcessor"/> 

<message-resources parameter="MessageResources"/> 

<plug-in className=

"org.apache.struts.tiles.TilesPlugin"> 

<set-property property="definitions-config" 

value="/WEB-INF/tiles-defs.xml"/> 

<set-property property="moduleAware" value="true"/> 

</plug-in> 

<plug-in className=

"org.apache.struts.validator.ValidatorPlugIn"> 

<set-property property="pathnames"

value="/WEB-INF/validator-rules.xml,

/WEB-INF/validation.xml"/> 

</plug-in> 

</struts-config>

到此我们可以运行测试程序了。

9、运行测试程序

右键点击testweb工程根目录,点击菜单中的Tomcate project->update context definition,将工程部署进tomcat,成功后会提示操作成功。

点击菜单栏中的雄猫图标启动tomcat,然后在IE地址栏中输入http://localhost:8080/testweb/index.do,我们会看到index.jsp的页面内容。

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:jsp入门学习教程

下一篇:利用Eclipse开发Hibernate应用程序