论坛首页 入门技术论坛

在Eclipse下实践Struts(不用Struts IDE) 二

浏览 1595 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-09-26  
改了一下,只贴代码了:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>utest</display-name>
<filter>
<display-name>struts2</display-name>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
</web-app>


index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<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">
</head>
<body>
<form action="hello.action" method="post">
<fieldset><legend>Struts2入门实例</legend>
<p><label>请输入你想说的话:</label>
<input type="text" name="helloWorld" value="buddy" /></p>
<p><input type="submit" value="提交" /></p>
</fieldset>
</form>
</body>
</html>


success.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <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">
</head>

<body>
    <s:property value="helloWorld" /> <br>
</body>
</html>


struts.xml
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
    <include file="struts-default.xml" />

    <package name="default" extends="struts-default">
        <action name="hello"
            class="com.yeepal.test.HelloAction">
            <result name="success">success.jsp</result>
            <result name="input">index.jsp</result>
        </action>

    </package>
</struts>


HelloAction.java
package com.yeepal.test;

import com.opensymphony.xwork2.ActionSupport;

public class HelloAction extends ActionSupport {
    private static final long serialVersionUID = 1L;

    private String helloWorld;
   
    public String getHelloWorld() {
        return helloWorld;
    }

    public void setHelloWorld(String helloWorld) {
        this.helloWorld = helloWorld;
    }

    public String execute() throws Exception {
        return SUCCESS;
    }
}
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics