你好,游客 登录 注册 搜索
背景:
阅读新闻

Struts2环境搭建以及第一个应用

[日期:2013-01-20] 来源:Linux社区  作者:howlaa [字体:大 中 小]

启动不报错,环境搭建完成。

第一个应用:

1、配置struts.xml配置文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">


<struts>
 <package name="wangfeng" namespace="/test" extends="struts-default">
  <action name="helloworld" class="com.feng.action.HelloWorldAction" method="execute">
   <result name="success">/WEB-INF/page/hello.jsp</result>
  </action>
 </package>
</struts>

2、建立action对应的类。

package com.feng.action;


public class HelloWorldAction {
 private String msg;
 
 public String getMessage() {
  return msg;
 }

 


 public String execute(){
  msg = "我的第一个Struts应用";
  return "success";
 }
}

3、配置视图hello.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 'hello.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>
    ${message}  <br>
  </body>
</html>

浏览器输入:http://localhost:8080/struts2/test/helloworld

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款