Struts2小白,报404了求教

nichilemaworld 2015-01-29 12:25:41
本人刚开始学Struts2框架,看着书上敲了第一个工程,但404了,弄了半天没解决,求大神指教!感激不尽!这是我的login.jsp和web.xml的代码:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<s:form action="login" method="post" namespace="/">
<s:textfield name="username" label="用户名" cssStyle="width:160px;height:26px;"/>
<s:password name="password" label="密码" cssStyle="width:160px;height:26px;"/>
<s:submit value="登 陆"/>
</s:form>
</body>
</html>

以下为web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>ch1</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>struts.i18n.encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
</web-app>

...全文
318 19 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
Coder_D 2015-01-29
  • 打赏
  • 举报
回复
Struts2核心拦截器你配置的是拦截*.action和*.jsp结尾的URL 但是你提交表单的时候提交路径是login 改成login.action
nichilemaworld 2015-01-29
  • 打赏
  • 举报
回复
那个报错也解决了,只要把工程重新创建一遍,重新在库里导入tomcat,就可以了,此贴终结!
nichilemaworld 2015-01-29
  • 打赏
  • 举报
回复
404解决了!妈的,按着书上说的做,结果是因为缺包,导入commons-lang3-3.2.jar这个包就行了,想再问大家一下这个报错正常么??虽然报错,但是不影响程序运行,有谁知道为啥报这个错么?? 一月 29, 2015 3:08:22 下午 org.apache.catalina.core.StandardContext filterStart 严重: Exception starting filter struts2 java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
wu244534279 2015-01-29
  • 打赏
  • 举报
回复
<result name="success">/success.jsp</result> 里的/success.jsp,前面那/不要 web.xml <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
  • 打赏
  • 举报
回复
第一个jsp页面是能进的是吧, 那就是后面提交的问题 你各种方法试试吧,我也没看出来
nichilemaworld 2015-01-29
  • 打赏
  • 举报
回复
引用 12 楼 wu244534279 的回复:
看看配置文件名,是否为struts.xml吧,这个很多新人都会写错的。 还有,先测试一下你的web项目是否部署成功了。
配置文件名没写错,怎么测试web是否部署成功了
nichilemaworld 2015-01-29
  • 打赏
  • 举报
回复
引用 11 楼 shijing266 的回复:
[quote=引用 6 楼 shijing266 的回复:] 表单form 的action属性这样写试试 : <%=basePath %>login.action
ctrl+c ——> ctrl + v [/quote] 刚才试了一下,不行啊
nichilemaworld 2015-01-29
  • 打赏
  • 举报
回复
这个是工程目录,大伙帮忙看下,有没有什么问题
wu244534279 2015-01-29
  • 打赏
  • 举报
回复
看看配置文件名,是否为struts.xml吧,这个很多新人都会写错的。 还有,先测试一下你的web项目是否部署成功了。
  • 打赏
  • 举报
回复
引用 6 楼 shijing266 的回复:
表单form 的action属性这样写试试 : <%=basePath %>login.action
ctrl+c ——> ctrl + v
nichilemaworld 2015-01-29
  • 打赏
  • 举报
回复
引用 5 楼 u012171905 的回复:
[quote=引用 4 楼 nichilemaworld 的回复:] 这是 Struts。xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"http://struts.apache.org/dtds/struts-2.1.7.dtd">
<struts>
	<package name="default" extends="struts-default" namespace="/">
		<action name="login" class="action.LoginAction">
			<result name="success">/success.jsp</result>
			<result name="input">/login.jsp</result>
		</action>
	</package>
</struts>
确认下类路径是否正确 还不行,拦截器改为/*试试 一般用的时候都是/*[/quote] 还是不行
nichilemaworld 2015-01-29
  • 打赏
  • 举报
回复
引用 7 楼 zhangning2147 的回复:
action 用绝对路径试试 action="<%= request.getContextPath()%>/login"
还是不行
nichilemaworld 2015-01-29
  • 打赏
  • 举报
回复
引用 6 楼 shijing266 的回复:
表单form 的action属性这样写试试 : <%=basePath %>login.action
能不能说具体点,整个标签应该怎么写??本人小白,比较笨
zhangning2147 2015-01-29
  • 打赏
  • 举报
回复
action 用绝对路径试试 action="<%= request.getContextPath()%>/login"
  • 打赏
  • 举报
回复
表单form 的action属性这样写试试 : <%=basePath %>login.action
Coder_D 2015-01-29
  • 打赏
  • 举报
回复
引用 4 楼 nichilemaworld 的回复:
这是 Struts。xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"http://struts.apache.org/dtds/struts-2.1.7.dtd">
<struts>
	<package name="default" extends="struts-default" namespace="/">
		<action name="login" class="action.LoginAction">
			<result name="success">/success.jsp</result>
			<result name="input">/login.jsp</result>
		</action>
	</package>
</struts>
确认下类路径是否正确 还不行,拦截器改为/*试试 一般用的时候都是/*
nichilemaworld 2015-01-29
  • 打赏
  • 举报
回复
这是 Struts。xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"http://struts.apache.org/dtds/struts-2.1.7.dtd">
<struts>
	<package name="default" extends="struts-default" namespace="/">
		<action name="login" class="action.LoginAction">
			<result name="success">/success.jsp</result>
			<result name="input">/login.jsp</result>
		</action>
	</package>
</struts>
Coder_D 2015-01-29
  • 打赏
  • 举报
回复
引用 2 楼 nichilemaworld 的回复:
[quote=引用 1 楼 u012171905 的回复:] Struts2核心拦截器你配置的是拦截*.action和*.jsp结尾的URL 但是你提交表单的时候提交路径是login 改成login.action
改了之后还是404[/quote]struts.xml文件贴出来看看
nichilemaworld 2015-01-29
  • 打赏
  • 举报
回复
引用 1 楼 u012171905 的回复:
Struts2核心拦截器你配置的是拦截*.action和*.jsp结尾的URL 但是你提交表单的时候提交路径是login 改成login.action
改了之后还是404

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧