struts2初体验(附视频)

本文主要讲述struts2的基本配置,注意是基本配置,struts2的配置不仅仅是这些。主要是为了演示第一个程序,所以本人认为越简单越好。

大多的配置基本和webwork相同。如果你会webwork只需要你5分钟的时间。

Web.xml文件添加代码如下:

xml 代码
 
  1. xml version="1.0" encoding="UTF-8"?>  
  2. <web-app version="2.4"   
  3.     xmlns="http://java.sun.com/xml/ns/j2ee"   
  4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  5.     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   
  6.     http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">  
  7.     <filter>  
  8.         <filter-name>strutsfilter-name>  
  9.         <filter-class>org.apache.struts2.dispatcher.FilterDispatcherfilter-class>  
  10.     filter>  
  11. <filter-mapping>  
  12.         <filter-name>strutsfilter-name>  
  13.         <url-pattern>/*url-pattern>  
  14.     filter-mapping>  
  15. web-app>  

建一个index.jsp页面如下:

<%@ page contentType="text/html; charset=GBK"%><o:p></o:p>

<%@ taglib prefix="s" uri="/struts-tags"%><o:p></o:p>

<html><o:p></o:p>

    <head><o:p></o:p>

       <title>indextitle><o:p></o:p>

    head><o:p></o:p>

    <body><o:p></o:p>

       <s:form action="index"><o:p></o:p>

           <s:textfield name="userName" label="enter your name">s:textfield><o:p></o:p>

           <s:submit /><o:p></o:p>

       s:form><o:p></o:p>

    body><o:p></o:p>

html><o:p></o:p>

建一个IndexAction类代码如下:

java 代码
 
  1. package com.test.struts2;  
  2. import com.opensymphony.xwork2.ActionSupport;  
  3. @SuppressWarnings("serial")  
  4. public class IndexAction extends ActionSupport{  
  5.     
  6.     private String userName;这里的个名字要和表单的名字一样  
  7.   
  8.     public String getUserName() {  
  9.         return userName;  
  10.     }  
  11.     public void setUserName(String userName) {  
  12.         this.userName = userName;  
  13.     }  
  14.     public String sayHello() throws Exception {  
  15.         return SUCCESS;  
  16.     }  
  17. }  

建立struts2的核心配置文件:struts.xml代码如下:<o:p></o:p>

xml 代码
 
  1. xml version="1.0" encoding="UTF-8" ?>  
  2.     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"  
  3.     "http://struts.apache.org/dtds/struts-2.0.dtd">  
  4. <struts>  
  5.     <include file="struts-default.xml" />  
  6.     <package name="default" extends="struts-default">  
  7.         <action name="index" class="com.test.struts2.IndexAction" method="sayHello">  
  8.             <result name="success" type="freemarker">/main1.ftlresult>  
  9.         action>  
  10.     package>  
  11. struts>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值