- kyo100900
- 等级:
- 性别:
- 文章: 173
- 积分: 620
- 来自: 北京
|
开始使用的是Struts2.06版本。在配置Struts.xml的时候,发现了一个问题:
struts.xml代码:
xml 代码
- <!---->
- "http://struts.apache.org/dtds/struts-2.0.dtd">
- <struts>
- <include file="struts-default.xml" />
- <package name="default" extends="struts-default">
-
- <interceptors>
- <interceptor-stack name="strutsStack">
- <interceptor-ref name="exception" />
- <interceptor-ref name="alias" />
- <interceptor-ref name="servlet-config" />
- <interceptor-ref name="prepare" />
- <interceptor-ref name="i18n" />
- <interceptor-ref name="chain" />
- <interceptor-ref name="debugging" />
- <interceptor-ref name="profiling" />
- <interceptor-ref name="scoped-model-driven" />
- <interceptor-ref name="model-driven" />
- <interceptor-ref name="fileUpload" />
- <interceptor-ref name="checkbox" />
- <interceptor-ref name="static-params" />
- <interceptor-ref name="params" />
-
- <interceptor-ref name="validation">
- <param name="excludeMethods">
- input,back,cancel,browse
- param>
- interceptor-ref>
- <interceptor-ref name="workflow">
- <param name="excludeMethods">
- input,back,cancel,browse
- param>
- interceptor-ref>
- interceptor-stack>
- interceptors>
-
- <default-interceptor-ref name="strutsStack" />
- package>
-
- <include file="struts_xml/user.xml" />
-
- struts>
这是struts.xml所包含的代码。
xml 代码
- <!---->
- "http://struts.apache.org/dtds/struts-2.0.dtd">
- <struts>
-
- <package name="user" extends="default">
-
- <action name="userAction"
- class="com.leo.controller.UserController" method="userAction">
- <result name="success">a.jspresult>
- <result name="input">login.jspresult>
- action>
-
- <action name="index" class="com.leo.controller.UserController"
- method="index">
- <result name="success">login.jspresult>
- <result name="input">login.jspresult>
- action>
-
- <action name="login" class="com.leo.controller.UserController"
- method="login">
- <result name="success" type="redirect-action">
- index.action
- result>
- <result name="input">login.jspresult>
- action>
-
- <action name="logout" class="com.leo.controller.UserController"
- method="logout">
- <result name="success">login.jspresult>
- <result name="input">login.jspresult>
- action>
-
- package>
-
- struts>
这种“包”继承关系是合法的,但在struts2.06版本怎么也无法通过,控制台一直报错:Error building results for action ××× in namespace - action 。调试了很久,Webwork文档与书也翻了N遍,还是没有效果。最后实在没有办法了,换成Struts2.09包,竟然通过了。
大家可以试试,其实Struts2的包继承是非常有用的,很多全局拦截器的设置,Action的设置,以及Result-type等,都可以通过包继承来组织你的配置文件。
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
返回顶楼 |
|
|
- topcloud
- 等级: 初级会员
- 性别:
- 文章: 39
- 积分: 58
- 来自: 西安
|
怎么才知道啊,哈哈!
|
返回顶楼 |
|
|
- totobacoo
- 等级: 初级会员
- 文章: 48
- 积分: 73
- 来自: K星座
|
http://www.iteye.com/topic/89919
老问题了
|
返回顶楼 |
|
|
- Sharp
- 等级: 初级会员
- 性别:
- 文章: 2
- 积分: 30
- 来自: 上海
|
了解!
|
返回顶楼 |
|
|
- jalinhu
- 等级: 初级会员
- 性别:
- 文章: 1
- 积分: 30
- 来自: 上海
|
java 代码
- import java.net.*;
- import java.io.*;
- import java.util.*;
-
- public class UDPServer {
- static final int INPORT = 1711;
- private byte[] buf = new byte[1000];
- private DatagramPacket dp = new DatagramPacket(buf, buf.length);
- private DatagramSocket socket;
- public UDPServer() {
- try {
- socket = new DatagramSocket(INPORT);
- System.out.println("Server started!");
- while (true) {
- socket.receive(dp);
- String rcvd = Dgram.toString(dp) + ",from ddress:" + dp.getAddress() +
- ",port:" + dp.getPort();
- System.out.println(rcvd);
- String echoString = "Echoed:" + rcvd;
- DatagramPacket echo = Dgram.toDatagram(echoString, dp.getAddress(),
- dp.getPort());
- socket.send(echo);
- }
- }
- catch (SocketException e) {
- System.err.println("Can't open socket");
- System.exit(1);
- }
- catch (IOException e) {
- System.err.println("Communication error!");
- e.printStackTrace();
- }
- }
-
- public static void main(String[] args) {
- new UDPServer();
- }
- }
-
-
- class UDPClient
- extends Thread {
- private DatagramSocket s;
- private InetAddress hostAddress;
- private byte[] buf = new byte[1000];
- private DatagramPacket dp = new DatagramPacket(buf, buf.length);
- private int id;
-
- public UDPClient(int identifier) {
- id = identifier;
- try {
- s = new DatagramSocket();
- hostAddress = InetAddress.getByName("localhost");
- }
- catch (UnknownHostException e) {
- System.err.println("Cannot find host");
- System.exit(1);
- }
- catch (SocketException e) {
- System.err.println("Can't open Socket");
- e.printStackTrace();
- System.exit(1);
- }
- }
-
- public void run() {
- try {
- for (int i = 0; i < 1; i++) {
- String outMessage = "Client #" +
- id + ",message#" + i;
- s.send(Dgram.toDatagram(outMessage, hostAddress, UDPServer.INPORT));
- s.receive(dp);
- String rcvd = "Client #" + id + ",rcvd from " +
- dp.getAddress() + "," +
- dp.getPort() + ":" +
- Dgram.toString(dp);
- System.out.println(rcvd);
- }
- }
- catch (IOException e) {
- e.printStackTrace();
- System.exit(1);
- }
- }
-
- public static void main(String[] args) {
- for (int i = 0; i < 1; i++)
- new UDPClient(i).start();
- }
- }
-
- class Dgram {
- public static DatagramPacket toDatagram(
- String s, InetAddress destIA, int destPort) {
- byte[] buf = new byte[s.length() + 1];
- s.getBytes(0, s.length(), buf, 0);
- return new DatagramPacket(buf, buf.length, destIA, destPort);
- }
-
- public static String toString(DatagramPacket p) {
- return new String(p.getData(), 0, p.getLength());
- }
- }
|
返回顶楼 |
|
|
- dimscar
- 等级: 初级会员
- 性别:
- 文章: 12
- 积分: 30
- 来自: 杭州
|
真不知道为什么,webwork2.0变成了这样的Struts2.0,真叫晕倒!
|
返回顶楼 |
|
|
- hmx_x
- 等级: 初级会员
- 性别:
- 文章: 1
- 积分: 30
- 来自: 北京
|
|
返回顶楼 |
|
|