当前位置:编程学习 > JAVA >>

struts2.2.3 configuration

 

struts2.2.3 madatory jar packages:

struts2-core-2.2.3.jar

xwork-core-2.2.3.jar

commons-fileupload-1.2.2.jar

commons-io-2.0.1.jar

commons-lang-2.5.jar

commons-logging-1.1.1.jar

freemarker-2.3.16.jar

javassist-3.11.0.GA.jar (This one's location is different. You need use winrar to open one of files in apps (struts2-blank.war). it is in the src dictory)

ognl-3.0.1.jar

 

Errors:

java.lang.NoClassDefFoundError: org/apache/commons/io/FileUtils

lack of commons io package

java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils

lack of commons lang package

java.lang.ClassNotFoundException: javassist.ClassPool

lack of javassist package

The following is an example:

login.jsp inputs username and password, then show them in result.jsp

login.jsp

<body>

  <form action="login">

    username: <input type="text" name="username"/><br/>

    password: <input type="password" name="password"/><br/>

    <input type="submit" value="submit"/>

  </form>

</body>

result.jsp

<body>

  username: ${requestScope.username }<br>

  password: ${requestScope.password }<br>

</body>

Server part:

package com.junxu.struts2;

 

public class LoginAction

{

    private String username;

    private String password;

    

    public String getUsername()

    {

        return username;

    }

    public void setUsername(String username)

    {

        this.username = username;

    }

    public String getPassword()

    {

        return password;

    }

    public void setPassword(String password)

    {

        this.password = password;

    }

    

    public String execute()

    {

        return "success";

    }

}

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="struts2" extends="struts-default">

        <action name="login" class="com.junxu.struts2.LoginAction">

            <result name="success">/result.jsp</result>

        </action>

    </package>

</struts>

web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5" 

    xmlns="http://java.sun.com/xml/ns/javaee" 

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 

    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

 

    <filter>

        <filter-name>struts2</filter-name>

        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

    </filter>

    

    <filter-mapping>

        <filter-name>struts2</filter-name>

        <url-pattern>/*</url-pattern>

    </filter-mapping>

    

</web-app>

 

本文出自 “笨鸟先飞” 博客

补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,