简单的struts创建

    xiaoxiao2021-03-25  105

    (1)点击MyEclipse菜单栏File按钮,点击new-->Web Project

    (2)项目创建完成——然后右键项目——点击MyEclipse-->Add Struts Capabilities ...-->选中2.1

    (3)点击finish,多出下边的sturs.xml

    (3)创建action包下边的类,名为  HelloAction

    package action; public class HelloAction {  public String execute() throws Exception{               System.out.println("执行Action");        return "success";    } }

    (4)在struts.xml中添加包和类

    <?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>  <package name="default"  extends="struts-default">            <action name="helloworld" class="action.HelloAction">                 <result name="success">/result.jsp</result>            </action>    </package> </struts>   

    (5)在创建result.jsp

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html>   <head>     <base href="<%=basePath%>">          <title>My JSP 'result.jsp' starting page</title>      <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0">     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> -->   </head>      <body>     This is my result.jsp page. <br>   </body> </html>

    (6)创建index.jsp,通过点击调用sturts

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html>   <head>     <base href="<%=basePath%>">          <title>文件上传</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0">     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> -->   </head>      <body>     This is my JSP page. <br>     <a href="helloworld.action">点击按钮</a>   </body> </html>

    (7)发布项目,点击链接,成功跳转。

    转载请注明原文地址: https://ju.6miu.com/read-8290.html

    最新回复(0)