qq_33826535 2016-08-24 02:38 采纳率: 0%
浏览 912
已结题

关于Struts2的配置,求指点。谢谢

There is no Action mapped for namespace / and action name user_login.
初学框架,不知道哪里写错了。求指点!

图片说明

login.jsp

 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s"  uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

    <title>用户登录</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    <s:head/>
  </head>

  <body>
    <center>
        <h1>用户登录</h1>
        <!-- <s:a action="user_addUI" namespace="/user">添加新用户</s:a> -->
        <s:form action="user_login" namespae="/user" method="post">
            <s:textfield label="用户名" name="user.username"></s:textfield>
            <s:password label="密码" name="user.password"></s:password>
            <s:submit value="登录"></s:submit>
        </s:form>
    </center>
  </body>
</html>

userList.jsp

 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s"  uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>

    <title>用户列表</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">   

  </head>

  <body>
    <center>
        <h2>用户列表</h2>
        <!-- <h3><s:a action="user_addUI" namespace="/">添加新用户</s:a> </h3> -->
        <table width="90%" border="1">
            <tr>
                <th>用户id</th>
                <th>用户名称</th>
                <th>用户密码</th>
                <th>操作</th>
            </tr>
            <s:iterator  value="userList">
                <tr>
                    <td><s:property value="id"/> </td>
                    <td><s:property value="username"/> </td>
                    <td><s:property value="password"/> </td>
                    <%-- <td><s:a action="user_updateUI" namespace="/user"><s:param name="user.id">${id}</s:param>修改</s:a>
                    &nbsp;&nbsp;<s:a action="user_delete" namespace="/user"><s:param name="user.id">${id}</s:param>删除</s:a></td> --%>
                </tr>
            </s:iterator>
        </table>
    </center>
  </body>
</html>

Struts.xml

 <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>    
     <constant name="struts.i18n.encoding" value="UTF-8"/>
    <constant name="struts.configuration.xmlreload" value="true"/>
    <constant name="struts.devMode" value="true"/>
    <constant name="struts.ui.theme" value="xhtml"/>

    <package name="user" namespace="/user" extends="struts-default">
        <action name="user_*" class="com.chen.action.UserAction" method="{1}">
            <result name="success" type="redirectAction">user_queryInfo.action</result>
            <result name="input">/index.jsp</result>
            <result name="userList">/userList.jsp</result>
        </action>
    </package>
</struts>    

UserAction

 package com.chen.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.chen.entity.User;
import com.chen.service.UserService;
import com.opensymphony.xwork2.ActionSupport;
@Controller
@Scope("prototype")
public class UserAction extends ActionSupport{
    @Autowired
    private UserService userService;
    private User user;
    private List<User> userList;
    public String execute() throws Exception {
        return null;
    }
    public String login() {
        if (user != null) {
            User user2 = userService.login(user);
            if (user2 != null) {
                return SUCCESS;
            }
        }
        this.addFieldError("user.username", "用户名或密码错误!");
        return INPUT;
    }

    public String queryInfo() {
        userList = userService.queryInfo(user);
        return "userList";
    }

}
  • 写回答

6条回答 默认 最新

  • 倾心静听 2016-08-24 02:41
    关注

    struts.xml的配置有没有配置,可以贴出来看下,这种错误一般是配置有问题引起的



    /online/datashow/list.jsp
    /online/datashow/listlog.jsp

    评论

报告相同问题?

悬赏问题

  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题