为了让我们以后开发方便,我们需要配置struts.xml的dtd的头,这样在编写struts.xml文件中可以有提示!
操作如下:
(1)打开myeclipse→window→Preferences→输入xml→XML→XML Catalog→Add→点击File System找到struts-2.1.7.dtd文件→在Key:输入-//Apache Software Foundation//DTD Struts Configuration 2.0//EN→勾选Specify alternative web address→在复选框下的输入框输入:http://struts.apache.org/dtds/struts-2.0.dtd→ok→ok
1.创建如下项目目录结构
2.在WebRoot下窗前index.jsp文件
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 <%@taglib uri="/struts-tags" prefix="s" %> 3 <% 4 String path = request.getContextPath(); 5 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 6 %> 7 8 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 9 <html> 10 <head> 11 <base href="<%=basePath%>"> 12 13 <title>My JSP 'index.jsp' starting page</title> 14 <meta http-equiv="pragma" content="no-cache"> 15 <meta http-equiv="cache-control" content="no-cache"> 16 <meta http-equiv="expires" content="0"> 17 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 18 <meta http-equiv="description" content="This is my page"> 19 <!-- 20 <link rel="stylesheet" type="text/css" href="styles.css"> 21 --> 22 </head> 23 24 <body> 25 <h1> 26 <s:property value="message"/> 27 </h1> 28 <hr/> 29 <form action="helloWorld.action" method="post"> 30 用户名:<input type="text" name="user"/> 31 <input type="submit" value="提交" /> 32 </form> 33 34 </body> 35 </html>