Evian_Tian 2016-12-07 07:11 采纳率: 0%
浏览 1044

There is no Action mapped for namespace

使用的是J2EE+SHH框架,

具体代码如下:

struts.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">
<struts>
    <constant name="struts.custom.i18n.resources" value="message" />
    <constant name="struts.i18n.encoding" value="UTF-8" />

    <!-- 指定Struts 2默认的ObjectFactory Bean - 交给Spring管理 -->
    <constant name="struts.objectFactory" value="spring" />
    <!-- 开发者模式 -->
    <!-- <constant name="struts.devMode" value="true" /> -->
    <!-- 指定每次配置文件更改后,自动重新加载 -->  
    <constant name="struts.configuration.xml.reload" value="false" />

</struts>

applicationContext.xml

**<?xml version="1.0" encoding="UTF-8"?>
<!-- context是自动扫描和使用注解的上下文前缀;aop,tx是事物管理的前缀 -->**
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-3.0.xsd
                        http://www.springframework.org/schema/aop
                        http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
                        http://www.springframework.org/schema/tx 
                        http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                        http://www.springframework.org/schema/task 
                        http://www.springframework.org/schema/task/spring-task-3.0.xsd"
                        default-autowire="byName">

    <!-- 采用自动扫描的方式查找bean(DAO,Service等等),多个用逗号隔开 -->
    <context:component-scan base-package="com.cheer.bookshop" />
    <!-- 定时器任务  -->
    <task:annotation-driven />

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <description>配置数据源</description>
        <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
        <property name="url" value="jdbc:mysql://localhost:3306/bookstore?useUnicode=true&amp;characterEncoding=UTF-8"></property>
        <property name="username" value="root"></property>  
        <property name="password" value="123456"></property>   
        <!-- 初始化连接数量 -->
        <property name="initialSize" value="1"/>
        <!-- 最大活动连接数量,一般等于数据库的最大并发数 -->
        <property name="maxActive" value="100"/>
        <!-- 最大空闲(等待)连接数量  -->
        <property name="maxIdle" value="-1"/>
        <!-- 最小空闲(等待)连接数量 -->
        <property name="minIdle" value="0"/>
        <!-- 获取连接时等待时间,超出将抛异常,单位毫秒 -->
        <property name="maxWait" value="10000"/>
    </bean>

    <!-- 配置hibernate session工厂 -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <description>将数据源注入到sessionFactory,使用注解方式</description>
        <property name="dataSource" ref="dataSource"></property>

        <!-- 配置hibernate的一些属性 -->
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.current_session_context_class">thread</prop> 
                <prop key="hibernate.connection.release_mode">after_transaction</prop><!-- 释放session -->
            </props>
        </property>

        <!-- 自动扫描注解方式配置的hibernate映射文件(实体类) -->
        <property name="packagesToScan">
            <list>
                <value>com.cheer.bookshop.Model</value>
            </list>
        </property>
    </bean>

    <!-- 定义事务管理器 -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <description> 增加事务管理</description>
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    <!-- 拦截器方式配置事务特性 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="add*" propagation="REQUIRED" />
            <tx:method name="delete*" propagation="REQUIRED" />
            <tx:method name="update*" propagation="REQUIRED" />
        </tx:attributes>
    </tx:advice>

    <!-- 给business配置事务管理 -->
    <aop:config proxy-target-class="true">
        <aop:pointcut id="allManagerMethod" expression="execution (* com.cheer.bookshop.*.*(..))" />
        <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod" />
    </aop:config> 

</beans>

JSP页面登陆Form表单

          <s:form action="userlogin.action" method="post">
          <p><font color="red">&nbsp;&nbsp;&nbsp;${msg}</font></p>
            <div class="form_row">
              <label class="contact"><strong>Username:</strong></label>
              <input type="text" class="contact_input" name="user.username" value="${user.username}"/>
            </div>
            <div class="form_row">
              <label class="contact"><strong>Password:</strong></label>
              <input type="password" class="contact_input" name="user.password" value="${user.password}"/>

            </div>
            <div class="form_row">
              <div class="terms">
                <input type="checkbox" name="terms" />
                Remember me </div>
            </div>
            <div class="form_row">
                <input type="submit" class="register" value="login" />
            </div>
          </s:form>

Action类

package com.cheer.bookshop.action;

import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

import com.cheer.bookshop.Model.User;
import com.cheer.bookshop.service.impl.UserServiceImpl;
import com.opensymphony.xwork2.ActionSupport;


@Namespace("/")

public class UserAction extends ActionSupport {


    @Resource
    private UserServiceImpl userServiceImpl;
    private User user;
    private String msg;

    //用户登录
    @Action(value = "userlogin", results = {@Result(name = "success", location = "/index.jsp"),
            @Result(name = "input", location = "/jsp/user/myaccount.jsp", type = "redirect") })
    public String login(){
        User userdb = userServiceImpl.login(user.getUsername());
        if(userdb != null){
            String password = user.getPassword();
            if(password.equals(userdb.getPassword())){
                user=userdb;
                return SUCCESS;
            }else{
                msg="密码错误,请重新输入!";
                return INPUT;
            }
        }else{
            msg="用户名不存在,请注册!";
            return INPUT;
        }
    }

    //用户注册
    @Action(value = "userregister", results = {@Result(name = "success", location = "/jsp/user/myaccount.jsp", type = "redirect") })
    public String register(){
        userServiceImpl.register(user);
        return SUCCESS;


    }

    //验证用户名是否已经被使用
    @Action(value = "validateUsername")
    public String validateUsername() throws IOException{
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpServletResponse response = ServletActionContext.getResponse(); 
        response.setContentType("text/html;charset=UTF-8"); 
        String username = request.getParameter("username");
        boolean flag = userServiceImpl.validateUsername(username);
        if(flag){
            response.getWriter().println("<p><font color='red'>用户名已经存在</font></p>"); 
        }else{
            response.getWriter().println("<p><font color='green'>用户名可以使用</font></p>"); 
        }
        return NONE;

    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }               
}

如上,Action有配置userlogin,登陆页form表单提交路径也是一样,单就是无法调整至aciton里,eclipse也没有报错,该如何解决?
There is no Action mapped for namespace / and action name userlogin.

  • 写回答

1条回答 默认 最新

  • kun_hello 2016-12-07 07:22
    关注

    @Controller 加个这个注解

    评论

报告相同问题?

悬赏问题

  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频