当前位置: 代码迷 >> Eclipse >> MyEclipse8.5配置Struts2.1方法
  详细解决方案

MyEclipse8.5配置Struts2.1方法

热度:16   发布时间:2016-04-23 00:50:49.0
MyEclipse8.5配置Struts2.1步骤
步骤一:创建新的Web Project



步骤二:新项目上右击-->MyEclipse-->Add Struts Capabilities...



步骤三:选择Struts版本为Struts 2.1






步骤四:创建一个Action
Java代码 复制代码?收藏代码
  1. package?com.test.action; ??
  2. ??
  3. import?com.opensymphony.xwork2.ActionSupport; ??
  4. ??
  5. @SuppressWarnings("serial") ??
  6. public?class?TestAction?extends?ActionSupport?{ ??
  7. ???? ??
  8. ????@Override??
  9. ????public?String?execute()?throws?Exception?{ ??
  10. ???????System.out.println("Message:?TestAction!"); ??
  11. ???????return?SUCCESS; ??
  12. ????} ??
  13. }??
package com.test.action;import com.opensymphony.xwork2.ActionSupport;@SuppressWarnings("serial")public class TestAction extends ActionSupport {		@Override    public String execute() throws Exception {       System.out.println("Message: TestAction!");       return SUCCESS;    }}


步骤五:修改index.jsp文件
Html代码 复制代码?收藏代码
  1. <body>??
  2. ????<a?href="<%=path%>/test.action">test</a>??
  3. </body>??
	<body>		<a href="<%=path%>/test.action">test</a>	</body>


步骤六:创建welcome.jsp文件
(文件中的内容自行决定哈)


步骤七:配置struts.xml文件
Xml代码 复制代码?收藏代码
  1. <?xml?version="1.0"?encoding="UTF-8"??>??
  2. <!DOCTYPE?struts?PUBLIC?"-//Apache?Software?Foundation//DTD?Struts?Configuration?2.1//EN"?"http://struts.apache.org/dtds/struts-2.1.dtd">??
  3. <struts>??
  4. ????<include?file="struts-default.xml">include</include>??
  5. ????<package?name="Test"?namespace="/"?extends="struts-default">??
  6. ????????<action?name="test"?class="org.test.action.TestAction">??
  7. ????????????<result?name="success">/welcome.jsp</result>??
  8. ????????</action>??
  9. ????</package>??
  10. </struts>?????
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"><struts>	<include file="struts-default.xml">include</include>	<package name="Test" namespace="/" extends="struts-default">		<action name="test" class="org.test.action.TestAction">			<result name="success">/welcome.jsp</result>		</action>	</package></struts>    
  相关解决方案