Struts2小白练手小工程,报错500找了好久还是不知道错哪了,求大神指教

nichilemaworld 2015-01-30 10:41:19

这是报错信息,是说我第11行有错是吧,可这也没啥错啊。。。
这是user_add.jsp的代码

<%@ 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="adduser" method="post" namespace="/">
<s:textfield name="username" lable="用户名" size="15"/>
<s:password name="password" lable="密码" size="15"/>
<s:textfield name="name" lable="真实姓名" size="15"/>
<s:textfield name="age" lable="年龄" size="15"/>
<s:radio list="#{'男':'男','女':'女' }" name="sex" lable="性别" listKey="key" listValue="value"/>
<s:submit value="添加用户" align="center"/>
</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>chch2</display-name>
<welcome-file-list>
<welcome-file>user_add.jsp</welcome-file>
</welcome-file-list>
</web-app>

这是struts.xml的代码

<?xml version="1.0" encoding="UTF-8"?>
<struts>
<constant name="struts.i18n.encoding" value="GBK"/>
<package name="default" extends="struts-default" namespace="/">
<action name="adduser" class="action.AddUserAction">
<result name="success">/user_list.jsp</result>
</action>
</package>
</struts>

这是工程文件视图:

求大神指教啊,感激不尽
...全文
549 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
nichilemaworld 2015-02-02
  • 打赏
  • 举报
回复
引用 20 楼 shixitong 的回复:
就没有lable这个属性 而是label
凸(艹皿艹 )。。。。。。。我说怎么不显示属性里的内容呢。。。
nichilemaworld 2015-01-30
  • 打赏
  • 举报
回复
引用 10 楼 u012552543 的回复:
404....新建个项目吧。。把文件copy过去。。
这有关系么??
隐性埋名 2015-01-30
  • 打赏
  • 举报
回复
404....新建个项目吧。。把文件copy过去。。
nichilemaworld 2015-01-30
  • 打赏
  • 举报
回复
引用 7 楼 shixitong 的回复:
clean下项目,把你访问的路径贴出来

刚运行错了,应该是user_add.jsp,但还是404
nichilemaworld 2015-01-30
  • 打赏
  • 举报
回复
引用 7 楼 shixitong 的回复:
clean下项目,把你访问的路径贴出来

clean项目是什么意思??是clean Tomcat么??我清了后还是404,这是访问路径
shixitong 2015-01-30
  • 打赏
  • 举报
回复
clean下项目,把你访问的路径贴出来
nichilemaworld 2015-01-30
  • 打赏
  • 举报
回复
引用 3 楼 shixitong 的回复:
web.xml中加
<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>
filter对照你的struts2版本看下
不行,还是404
Coder_D 2015-01-30
  • 打赏
  • 举报
回复
引用 2 楼 nichilemaworld 的回复:
[quote=引用 1 楼 u012171905 的回复:] web.xml中struts2的拦截器配置了吗?
配置成这样可以么
<?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>chch2</display-name>
  <welcome-file-list>
    <welcome-file>user_add.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>
</web-app>
但是现在404了[/quote]你这样配置拦截的是以.action结尾的请求 但是你表单提交的时候没有按配置提交
野树林 2015-01-30
  • 打赏
  • 举报
回复
要在web.xml配置strust2的filter 看看
shixitong 2015-01-30
  • 打赏
  • 举报
回复
web.xml中加
<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>
filter对照你的struts2版本看下
nichilemaworld 2015-01-30
  • 打赏
  • 举报
回复
引用 1 楼 u012171905 的回复:
web.xml中struts2的拦截器配置了吗?
配置成这样可以么
<?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>chch2</display-name>
  <welcome-file-list>
    <welcome-file>user_add.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>
</web-app>
但是现在404了
Coder_D 2015-01-30
  • 打赏
  • 举报
回复
web.xml中struts2的拦截器配置了吗?
邹邹wl 2015-01-30
  • 打赏
  • 举报
回复
学习。。。。。。。。。。。
shixitong 2015-01-30
  • 打赏
  • 举报
回复
就没有lable这个属性 而是label
imbobo_bo 2015-01-30
  • 打赏
  • 举报
回复
引用 18 楼 imbobo_bo 的回复:
[quote=引用 17 楼 nichilemaworld 的回复:] [quote=引用 16 楼 imbobo_bo 的回复:] web.xml中 <url-pattern>*.action</url-pattern> 换成 <url-pattern>/*</url-pattern> 即可 把你的 <s:radio list="#{'男':'男','女':'女' }" name="sex" lable="性别" listKey="key" listValue="value"/> 中的lable="性别" 去掉
感谢你,真的可以了,不过性别那个lable不用去掉,还想问您下,/*和*.action有什么区别,为什么前者就不会报错。[/quote] lable可能是版本的问题,估计新版本可以使用了 /* 是你访问应用下的所有请求都被拦截,*.action 只是拦截以action结尾的请求 如果你配置的是/* 并且你直接访问jsp地址是不会被struts拦截器的 [/quote] 不是/* 是 *.action 说反了
imbobo_bo 2015-01-30
  • 打赏
  • 举报
回复
引用 17 楼 nichilemaworld 的回复:
[quote=引用 16 楼 imbobo_bo 的回复:] web.xml中 <url-pattern>*.action</url-pattern> 换成 <url-pattern>/*</url-pattern> 即可 把你的 <s:radio list="#{'男':'男','女':'女' }" name="sex" lable="性别" listKey="key" listValue="value"/> 中的lable="性别" 去掉
感谢你,真的可以了,不过性别那个lable不用去掉,还想问您下,/*和*.action有什么区别,为什么前者就不会报错。[/quote] lable可能是版本的问题,估计新版本可以使用了 /* 是你访问应用下的所有请求都被拦截,*.action 只是拦截以action结尾的请求 如果你配置的是/* 并且你直接访问jsp地址是不会被struts拦截器的
nichilemaworld 2015-01-30
  • 打赏
  • 举报
回复
引用 16 楼 imbobo_bo 的回复:
web.xml中 <url-pattern>*.action</url-pattern> 换成 <url-pattern>/*</url-pattern> 即可 把你的 <s:radio list="#{'男':'男','女':'女' }" name="sex" lable="性别" listKey="key" listValue="value"/> 中的lable="性别" 去掉
感谢你,真的可以了,不过性别那个lable不用去掉,还想问您下,/*和*.action有什么区别,为什么前者就不会报错。
imbobo_bo 2015-01-30
  • 打赏
  • 举报
回复
web.xml中 <url-pattern>*.action</url-pattern> 换成 <url-pattern>/*</url-pattern> 即可 把你的 <s:radio list="#{'男':'男','女':'女' }" name="sex" lable="性别" listKey="key" listValue="value"/> 中的lable="性别" 去掉
nichilemaworld 2015-01-30
  • 打赏
  • 举报
回复
引用 14 楼 imbobo_bo 的回复:
楼主是直接在地址栏输入的是jsp的地址吧!!!!!!!!! 通过action跳转到个jsp就没问题了,直接访问包含struts2标签的jsp页面,也就是没经过struts2核心控制器直接访问jsp页面,就会报以上错,或者在web.xml配置文件配置过滤器也可以
web.xml里我已经配置了过滤器了,就按楼上几位说的那样配置的。我是在user_add.jsp代码页面上右键运行在服务器上的啊,您说的通过action跳转是怎么弄,能不能详细说说,本人小白,比较笨,谢谢!
imbobo_bo 2015-01-30
  • 打赏
  • 举报
回复
楼主是直接在地址栏输入的是jsp的地址吧!!!!!!!!! 通过action跳转到个jsp就没问题了,直接访问包含struts2标签的jsp页面,也就是没经过struts2核心控制器直接访问jsp页面,就会报以上错,或者在web.xml配置文件配置过滤器也可以
加载更多回复(2)

81,095

社区成员

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

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