??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲天天在线日亚洲洲精,亚洲一区二区女搞男,亚洲欧洲视频在线观看http://m.tkk7.com/softwin/category/19404.html快毕业了 :( 好好学习...天天向上 zh-cnTue, 10 Apr 2007 00:46:51 GMTTue, 10 Apr 2007 00:46:51 GMT60Struts2入门教程QHello Worldhttp://m.tkk7.com/softwin/archive/2007/04/09/109494.html伽蓝伽蓝Mon, 09 Apr 2007 13:14:00 GMThttp://m.tkk7.com/softwin/archive/2007/04/09/109494.htmlhttp://m.tkk7.com/softwin/comments/109494.htmlhttp://m.tkk7.com/softwin/archive/2007/04/09/109494.html#Feedback0http://m.tkk7.com/softwin/comments/commentRss/109494.htmlhttp://m.tkk7.com/softwin/services/trackbacks/109494.html    当你向一个框架提交HTML表单的时候,输入的数据ƈ不是被发送到一个服务端面Q而是传送到一个你自己提供的称为Action的javac,产生的结果会选择一个资源来l制响应。该资源通常Z个服务端的页面,但也可以是一个pdf的文,也可以是一个Excel电子数据表格Q或者是Java appletH口?br>    假设你希望创Z个简单的“Hello World”例子来显C欢q消息。下载struts2的空web应用Q即struts2-blank-2.0.6.warQ,你需要做以下三g事:
1.创徏一个服务页面来展示消息
2.创徏一个ActioncL创徏消息
3.创徏一个连接Actioncd面的映?br>    让我们来看看q个ActionQ服务页面和映射的例子。如果你喜欢也可以用IDE来编辑代码?br>
代码如下Q?br>首先Q定义一个服务页面显C数?br><%@ taglib prefix="s" uri="/struts-tags" %>
<html>
        <head>
                 <title>Hello World!</title>
        </head>
        <body>
                 <h2><s:property value="message" /></h2>
        </body>
</html>
其次Q我们需要一个ActioncL创徏消息
package tutorial;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorld extends ActionSupport {
     
       public static final String MESSAGE = "Struts is up and running...";
       
       private String message;

       public String execute() throws Exception {
                setMessage(MESSAGE);
                return SUCCESS;
       }

        public void setMessage(String message) {
                this.message = message;
        }

        public String getMessage() {
                return message;
        }
}
最后我们需要一个映来l定所有?br>~辑struts.xml文g来添加HelloWorld映射
<!DOCTYPE struts PUBLIC
           "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
           "<struts>
          <package name="tutorial" extends="struts-default">
                    <action name="HelloWorld" class="tutorial.HelloWorld">
                              <result>/HelloWorld.jsp</result>
                    </action>
          </package>
</struts>
然后部v该应用程序,打开
http://localhost:8080/tutorial/HelloWorld.action观察出现了什么,你会看见一个标题ؓHello WorldQ的面q有一?#8220;Struts is up and running”的消息?br>
代码是如何工作的Q?br>1.容器接收到HelloWorld.action的请求。根据web.xml的设|,容器会寻找所有被发送到org.apache.struts2.dispatcher.FilterDispatcher的请求,包括所有的*.action的请求。FilterDispatcher是框架的入口炏V?br>2.框架L一个映名为HelloWorld的ActioncR它扑ֈ与HelloWorldcȝ关的映射Qƈ调用Action的executeҎ?br>3.executeҎ讄了消息ƈq回SUCCESS。如果返回的是SUCCESSQ框架会查ActioncL的哪个面被装蝲。框架会告诉容器l制HelloWorld.jsp作ؓh的响应?br>4.当HelloWorld.jsp被调用,<s:property value="message" />标签调用HelloWorld的ActioncȝgetterҎgetMessageQƈmessage的值合q到响应中去?br>5.一个纯_的响应被发送回览器?br>
试Actionsc,代码如下
package tutorizl
import junit.framework.TestCase;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class HelloWorldTest extends TestCase {
         public void testHelloWorld() throws Exception {
             
               HelloWorld hello_world = new HelloWorld();
               String results = hello_world.execute();

               assertTrue("Expected a success results!", ActionSupport.SUCCESS.equals(results));
  
               assertTrue("Expected the default message!",HelloWorld.MESSAGE.equals(hello_world.getMessage()));

        }
}

需要记住的?框架使用ActioncL处理HTML表单和其他请求,Actionc返回一个诸如SUCCESS,ERROR,或INPUT名称。根据来自struts.xml的映,一个返回的名称会选择相应的页面,另外的ActionQ或其他web资源Q图象,PDFQ?br>当一个服务端面被绘Ӟ大多情况下会包括由ActioncL供的动态数据。框架会提供一pd的HTML标签创徏面来得显C动态数据更加简单?/p>


 



伽蓝 2007-04-09 21:14 发表评论
]]>
再写一遍struts解决中文q问题http://m.tkk7.com/softwin/archive/2006/09/24/71558.html伽蓝伽蓝Sun, 24 Sep 2006 05:30:00 GMThttp://m.tkk7.com/softwin/archive/2006/09/24/71558.htmlhttp://m.tkk7.com/softwin/comments/71558.htmlhttp://m.tkk7.com/softwin/archive/2006/09/24/71558.html#Feedback3http://m.tkk7.com/softwin/comments/commentRss/71558.htmlhttp://m.tkk7.com/softwin/services/trackbacks/71558.html 在学习struts?遇到了中文ؕ码问?|上搜烦了一些资?解决了问?/font>

使用getҎ?需要修?$TOMCAT/conf/server.xml部v文g,在connectior属性中dURIEncoding="GBK"卛_

使用postҎ??U方法可?/font>

1) 覆写ActionServlet的processҎ,drequest.setEncoding("GBK");

2) d一个过滤器SetCharacterEncodingFilterc?此类可以?TOMCAT\webapps\servlets-examples\WEB-INF\classes\filters扑ֈ,不过方便赯,自己加了点东?源码如下:

public class SetCharacterEncodingFilter implements Filter {
 private FilterConfig filterConfig;

 public void destroy()
 {
  // TODO Auto-generated method stub
  
 }

 public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException
 {
  // TODO Auto-generated method stub
  try{
   request.setCharacterEncoding("GB2312");
   HttpServletResponse res = (HttpServletResponse)response;
   res.setHeader("Pragma", "No-cache");
   res.setHeader("Cache-Control", "no-cache");
   res.setHeader("Pragram", "no-cache");
   filterChain.doFilter(request, response);
  }catch(ServletException e)
  {
   filterConfig.getServletContext().log(e.getMessage());
  }catch(IOException e)
  {
   filterConfig.getServletContext().log(e.getMessage());
  }
 }

 public void init(FilterConfig filterConfig) throws ServletException
 {
  // TODO Auto-generated method stub
  this.filterConfig = filterConfig;
 }

}

在web.xml中部|这个过滤器

<filter>
    <filter-name>servfilter</filter-name>
    <filter-class>com.yourcompany.struts.SetCharacterEncodingFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>servfilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

 

关于国际化问?我曾l请教过老师,不过老师好像不是q个方向?/font>

后来才发现是一个很愚蠢的问?要求是ApplicationResources_zh_CN.properties或ApplicationResources_zh.properties 而我却用了ApplicationResources_cn.properties

切记CN是大写的

native2ascii -encoding gb2312 application_temp.properties  application_CN.properties

native2ascii可以?JAVA_HOME/bin下找?/font>



伽蓝 2006-09-24 13:30 发表评论
]]>
վ֩ģ壺 ȫƵѹۿ߿| žۺVAѿ| ˾ҹƵѹ| ƬѸ߿| ĻƵѹۿ| þù߳׽ѹۿ | av뾫Ʒַ| ɫӴӴƷѹۿ| պƵ| 99þѾƷ72Ʒž| ѳҹƵ| avh˶ڵ| fuli߹ۿ| һëƬѲһ| վavƬ| ѧһػƵѴƬƵ| ޾Ʒ鶹av| ҹƷӰ߹ۿ| | 13СϴƵվ| 㽶Ƶ| ִֻˬƵ| AVպAVþþ| ޳avƬ롿| ѲһëƬ| ŮݽƵѿ| ޹Ʒva߲| avһ| Ƶ߹ۿ | Ʒ69׽߹ۿ| ޹aƵ| ޹Ů߹ۿ| һƵ | ѳ˸Ƶ| Ƭѹۿ| þþƷAVվ| ޳aƬ2023| ҹˬˬˬŮѹۿӰԺ| ƷɫҹƵ| þ޾Ʒavվ| Ƶ|