程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> namespace-struts2注解url沒跳轉到action裡的方法,沒報錯也沒跳轉

namespace-struts2注解url沒跳轉到action裡的方法,沒報錯也沒跳轉

編輯:編程綜合問答
struts2注解url沒跳轉到action裡的方法,沒報錯也沒跳轉

我補下圖片:
圖片說明

package com.AppServer.action;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ExceptionMapping;
import org.apache.struts2.convention.annotation.ExceptionMappings;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

import com.AppServer.bean.User;
import com.AppServer.dao.UserDAO;
import com.AppServer.service.UserService;
import com.demo.interceptor.MethodCacheInterceptor;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

@Controller
@ParentPackage("struts-default")
@Namespace(value = "msgAction")
@ExceptionMappings({ @ExceptionMapping(exception = "java.lange.RuntimeException", result = "error") })

public class MsgAction extends ActionSupport {

private String username;
private String password;



@Resource
private UserService userService;

@Action(value = "msg" , results = { @Result(name = "success", location = "/success.jsp"),
        @Result(name = "failure", location = "/failure.jsp"),
        @Result(name = "error", location = "/login.jsp")})
//獲取用戶信息
public String getInfo() {
    System.out.println("進來玩");
    return SUCCESS;


}


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;
}

}

url訪問如下:http://127.0.0.1:8080/AppServer_1.1/msgAction/msg.do

訪問之後沒報錯,沒進去getInfo這個方法

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

<!-- 指定Web應用的默認編碼,相當於調用request的setCharacterEncoding方法 -->
<constant name="struts.i18n.encoding" value="UTF-8" />
<!-- 設置浏覽器是否緩存靜態內容,默認值為true(生產環境下使用),開發階段最好關閉 -->
<constant name="struts.serve.static.browserCache" value="false" />
<!-- 當Struts2的配置文件修改後,系統是否自動重新加載配置文件,默認值為false(生產環境下使用),開發階段最好打開 -->
<constant name="struts.configuration.xml.reload" value="true" />
<!-- 開發模式下使用,這樣可以打印出更詳細的日志信息 -->
<constant name="struts.devMode" value="true" />
<!-- 默認的視圖主題 -->
<constant name="struts.ui.theme" value="simple" />
<!-- 把Action對象交給Spring創建和管理 -->
<constant name="struts.objectFactory" value="spring" />
<!-- Struts2處理的請求後綴,默認值是action -->
<constant name="struts.action.extension" value="do" />

<!-- 國際化資源文件
<constant name="struts.custom.i18n.resources" value="globalMessages" />
 -->


<package name="msg" extends="struts-default">

    <default-action-ref name="indexPage" />

    <global-results>
        <result name="exceptionPage">/error/exceptionPage.jsp</result>
    </global-results>

    <global-exception-mappings>
        <exception-mapping result="exceptionPage" exception="java.lang.Exception" />
    </global-exception-mappings>

    <action name="indexPage">
        <result>/login.jsp</result>
    </action>

    <!-- <action name="msg" method="getInfo" class="com.AppServer.action.MsgAction">
        <result name="success">/success.jsp</result>
        <result name="failure">/failure.jsp</result>
        <result name="error">/login.jsp</result>
    </action> -->

</package>

application.xml:
<?xml version="1.0" encoding="UTF-8" ?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"
default-autowire="byName" default-lazy-init="true">

<!-- 說明:下面有的Bean配置提供了多種方案,請根據需要采用某一種(別忘了注釋掉其他同類方案) -->

<!-- 自動掃描Spring注解配置  並保證@Required,@Autowired的屬性被注入-->
<context:component-scan base-package="com" />

<!-- 自動加載屬性配置文件 -->
<context:property-placeholder location="classpath:jdbc.properties" />

<!-- 配置數據源:方法一,使用C3P0方式(推薦) -->
<!-- <context:property-placeholder location="classpath:jdbc.properties"/> -->  
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">  
   <property name="driverClassName" value="${jdbc.driverClassName}"/>  
   <property name="url" value="${jdbc.url}"/>  
   <property name="username" value="${jdbc.username}"/>  
   <!-- property池啟動時的初始值  -->  
    <property  name="password" value="${jdbc.password}"/>  
    <!-- 連接name="initialSize" value="${initialSize}"/>-->  
    <property name="initialSize" value="1"/>  
    <!-- 連接池的最大值 -->  
    <property name="maxActive" value="500"/>  
    <!-- 最大空閒值.當經過一個高峰時間後,連接池可以慢慢將已經用不到的連接慢慢釋放一部分,一直減少到maxIdle為止 -->  
    <property name="maxIdle" value="2"/>  
    <!--  最小空閒值.當空閒的連接數少於閥值時,連接池就會預申請去一些連接,以免洪峰來時來不及申請 -->  
    <property name="minIdle" value="1"/>  
</bean>  

<!-- 配置數據源:方法二,使用DBCP方式(不推薦) -->
<!-- 
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
    destroy-method="close" 
    p:driverClassName="${jdbc.driverClassName}" 
    p:url="${jdbc.url}" 
    p:username="${jdbc.username}" 
    p:password="${jdbc.password}" />
 -->

<!-- 配置數據源:方法三,使用JNDI方式 -->
<!-- 
<jee:jndi-lookup id="dataSource" jndi-name="${jndi.name}" />
 -->



<!-- 配置Hibernate的數據源代理工廠:方法一,使用p屬性通配符,按文件名搜索匹配的映射文件 -->
<!-- <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
    p:dataSource-ref="dataSource" >
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
            <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
            <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
            <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
            <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop>
        </props>
    </property>
    加載hibernate的jpa注解形式實體
    <property name="packagesToScan">
        <list>
            <value>com.xmm.demo.domain*</value>
        </list>
    </property>
</bean> -->
<!-- 配置Hibernate的數據源代理工廠:方法二,使用list集合,按文件名搜索匹配的映射文件 -->

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
    p:dataSource-ref="dataSource">
    <property name="mappingLocations">
        <list>
            <value>classpath*:/com/**/*.hbm.xml</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
            <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
            <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
            <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
            <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop>
        </props>
    </property>
</bean>

<!-- 配置Hibernate的數據源代理工廠:方法三,使用p屬性通配符,按目錄搜索映射文件 -->
<!-- 
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
    p:dataSource-ref="dataSource" p:mappingDirectoryLocations="classpath*:/com/**/domain">
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
            <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
            <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
            <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
            <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop>
        </props>
    </property>
</bean>
 -->
<!-- 配置Hibernate的數據源代理工廠:方法四,使用hibernate.cfg.xml -->
<!-- 
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
    p:dataSource-ref="dataSource" p:configLocation="classpath:hibernate.cfg.xml">
</bean>
 -->



<!-- 配置事務管理器 -->
<bean id="transactionManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager"
    p:sessionFactory-ref="sessionFactory" />


<!-- 配置聲明式事務:方法一,在Service實現類或者public實現方法上使用注解@Transactional,則此類或方法就會啟用事務機制 -->
<!-- <tx:annotation-driven transaction-manager="transactionManager" /> -->

<!-- 配置聲明式事務:方法二,使用tx/aop命名空間的配置(其實還有方法三,由於快要過時不推薦使用了,這裡就不給出方法三的配置了) -->

<tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
        <tx:method name="insert*" propagation="REQUIRED" />
        <tx:method name="update*" propagation="REQUIRED" />
        <tx:method name="edit*" propagation="REQUIRED" />
        <tx:method name="save*" propagation="REQUIRED" />
        <tx:method name="add*" propagation="REQUIRED" />
        <tx:method name="new*" propagation="REQUIRED" />
        <tx:method name="set*" propagation="REQUIRED" />
        <tx:method name="remove*" propagation="REQUIRED" />
        <tx:method name="delete*" propagation="REQUIRED" />
        <tx:method name="change*" propagation="REQUIRED" />
        <tx:method name="get*" propagation="REQUIRED" read-only="true" />
        <tx:method name="find*" propagation="REQUIRED" read-only="true" />
        <tx:method name="load*" propagation="REQUIRED" read-only="true" />
        <tx:method name="search*" propagation="REQUIRED" read-only="true" />
        <tx:method name="*" propagation="REQUIRED" read-only="true" />
    </tx:attributes>
</tx:advice>
<aop:config>
    <aop:pointcut id="mypointcut" expression="execution(* com.**.service..*.*(..))" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="mypointcut" />
</aop:config>




<!-- 下面三個Bean的配置可有可無,但配置後用處更大,通常用於BaseDao類、其他Dao類或特殊工具類中 -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate"
    p:sessionFactory-ref="sessionFactory" />

<bean id="hibernateDaoSupport" class="org.springframework.orm.hibernate4.support.HibernateDaoSupport"
    p:hibernateTemplate-ref="hibernateTemplate" abstract="true"/>

<bean id="sessionFactoryUtils" class="org.springframework.orm.hibernate4.SessionFactoryUtils" abstract="true"/>

tomcat6.0:服務器運行正常:
九月 21, 2015 4:22:24 上午 org.apache.catalina.core.AprLifecycleListener init
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\Java\jdk1.7.0\bin;E:\tomcat6\bin
九月 21, 2015 4:22:25 上午 org.apache.coyote.http11.Http11Protocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
九月 21, 2015 4:22:25 上午 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 516 ms
九月 21, 2015 4:22:25 上午 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
九月 21, 2015 4:22:25 上午 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.41
九月 21, 2015 4:22:25 上午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory AppServer_1.1
九月 21, 2015 4:22:25 上午 org.apache.catalina.loader.WebappClassLoader validateJarFile
信息: validateJarFile(E:\tomcat6\webapps\AppServer_1.1\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
九月 21, 2015 4:22:26 上午 org.apache.catalina.core.ApplicationContext log
信息: Set web app root system property: 'webapp.root' = [E:\tomcat6\webapps\AppServer_1.1]
九月 21, 2015 4:22:26 上午 org.apache.catalina.core.ApplicationContext log
信息: Initializing log4j from [classpath:log4j.properties]
九月 21, 2015 4:22:26 上午 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
九月 21, 2015 4:22:34 上午 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8080
九月 21, 2015 4:22:34 上午 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
九月 21, 2015 4:22:34 上午 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/23 config=null
九月 21, 2015 4:22:34 上午 org.apache.catalina.startup.Catalina start
信息: Server startup in 9364 ms

測試定時任務:2015-09-21 04:30:00:074

測試定時任務:2015-09-21 04:40:00:004

url訪問地址:http://127.0.0.1:8080/AppServer_1.1/msgAction/msg.do
沒有進去action的getinfo方法,這是為什麼?而且也沒有任何的報錯!!!!!!!!!!!

最佳回答:


沒錯啊,就是這個訪問url::http://127.0.0.1:8080/AppServer_1.1/msgAction/msg.do

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved