首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

structs2.0配备

2012-12-21 
structs2.0配置首先 我建立了struct项目在src下建立了个包叫:org.action,建立一个类叫:StrutsActionStruts

structs2.0配置
首先 我建立了struct项目
在src下建立了个包叫:org.action,建立一个类叫:StrutsAction

StrutsAction类内容如下:
package org.action;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class StrutsAction extends ActionSupport{
private String name;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name=name;
}

public String execute()throws Exception
{
if(getName().equals("hello"))
{

return "success";
    }
else
return "error";
}
}


index.jsp如下:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
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>My JSP 'index.jsp' starting page</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">
-->
  </head>
  
  <body>
    <form action="struts.action" method="post">
请输入姓名:<input type="text" name="name"/><br/>
<input type="submit" value="提交"/>
</form>
  </body>
</html>


error.jsp如下:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
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>My JSP 'error.jsp' starting page</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">
-->

  </head>
  
  <body>
 错误 <br>
  </body>
</html>


welcome.jsp如下 :
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<%
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>My JSP 'welcome.jsp' starting page</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">
-->

  </head>
  
  <body> 
    hello!
  </body>
</html>



我已经导入struts相应的jar包用bulid path方式
structs.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>
<package name="org.action" extends="struts-default">
<action name="struts.action" class="org.action.StrutsAction">
<result name="success">/welcome.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
</struts>

web.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

  <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>
</web-app>

打入地址:http://localhost:8080/struts2/index.jsp
输入hello

提交后,页面显示如下:
HTTP Status 404 - /struts2/struts.action

type Status report

message /struts2/struts.action

description The requested resource (/struts2/struts.action) is not available.
Apache Tomcat/7.0.2


不知什么原因,求赐教
[最优解释]
可以的话,把程序发我qq28205968,我帮你看看。
[其他解释]
<action name="struts.action" class="org.action.StrutsAction">
<result name="success">/welcome.jsp</result>
HTTP Status 404 - /struts2/struts.action

取名不规范,正常的action的name不要带上.action,因为这是struts2默认的。比如name="xxx",
url:/工程名/xxx 或者/工程名/xxx.action。
如果一定要这样写,那么就还得在你的<form action="struts.action.action" method="post">
试试吧!
------其他解决方案--------------------


lz,你的程序我运行过了,就两个地方,改了你就可以运行了。
1.struct.xml文件名写错了,应该是strut.xml
2.action的name不要带写后缀,对应index.jsp里面
3.我改过的strut.xml如下:


 "http://struts.apache.org/dtds/struts-2.3.dtd">
 <struts>

<!-- 访问路径的后缀 -->
<constant name="struts.action.extension" value="action,do" />

 <package name="org.action" extends="struts-default">
 <action name="struts.action" class="org.action.StrutsAction">
 <result name="success">/welcome.jsp</result>
 <result name="error">/error.jsp</result>
 </action>
 </package>
 </struts>
[其他解释]
改了报什么错啊?配置就那么回事!翻来覆去网上都说得明明白白的!
[其他解释]
顺便去查一下webapp下面的工程名是不是你建的工程名
[其他解释]

引用:
改了报什么错啊?配置就那么回事!翻来覆去网上都说得明明白白的!

java.net.BindException: Address already in use: JVM_Bind <null>:8009
at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:406)
at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:610)
at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:429)
at org.apache.catalina.connector.Connector.initInternal(Connector.java:981)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
at org.apache.catalina.core.StandardService.initInternal(StandardService.java:559)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:814)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
at org.apache.catalina.startup.Catalina.load(Catalina.java:624)
at org.apache.catalina.startup.Catalina.load(Catalina.java:649)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:281)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:450)
Caused by: java.net.BindException: Address already in use: JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
at java.net.ServerSocket.bind(ServerSocket.java:319)
at java.net.ServerSocket.<init>(ServerSocket.java:185)
at java.net.ServerSocket.<init>(ServerSocket.java:141)
at org.apache.tomcat.util.net.DefaultServerSocketFactory.createSocket(DefaultServerSocketFactory.java:49)
at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:393)
... 16 more
2012-12-1 12:04:10 org.apache.catalina.core.StandardService initInternal
严重: Failed to initialize connector [Connector[AJP/1.3-8009]]
org.apache.catalina.LifecycleException: Failed to initialize component [Connector[AJP/1.3-8009]]
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:106)
at org.apache.catalina.core.StandardService.initInternal(StandardService.java:559)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:814)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)


at org.apache.catalina.startup.Catalina.load(Catalina.java:624)
at org.apache.catalina.startup.Catalina.load(Catalina.java:649)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:281)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:450)
Caused by: org.apache.catalina.LifecycleException: Protocol handler initialization failed
at org.apache.catalina.connector.Connector.initInternal(Connector.java:983)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
... 12 more
Caused by: java.net.BindException: Address already in use: JVM_Bind <null>:8009
at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:406)
at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:610)
at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:429)
at org.apache.catalina.connector.Connector.initInternal(Connector.java:981)
... 13 more
Caused by: java.net.BindException: Address already in use: JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
at java.net.ServerSocket.bind(ServerSocket.java:319)
at java.net.ServerSocket.<init>(ServerSocket.java:185)
at java.net.ServerSocket.<init>(ServerSocket.java:141)
at org.apache.tomcat.util.net.DefaultServerSocketFactory.createSocket(DefaultServerSocketFactory.java:49)
at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:393)
... 16 more



第一个我百度过,是端口占用。但是我输入http://localhost:8080/struts2/index.jsp
还是可以访问index.jsp
[其他解释]
端口被占用 ,查看哪个服务占用了删除掉 ,或者重启电脑
[其他解释]
可能有两个原因:1.action名字不要带.action。
                2.加上namespace="/"。
[其他解释]

引用:
端口被占用 ,查看哪个服务占用了删除掉 ,或者重启电脑

但是我输入http://localhost:8080/struts2/index.jsp
还是可以访问index.jsp
[其他解释]
首先如13楼所说: 
1. action的name不要带写后缀, 如果写了, 浏览器上访问时就得写name的全称.action(如:struts.action.action);
2. 加上namespace="/XXX";
3.端口占用的问题,估计是你启动了多个Tomcat, 端口被自己占用!
4.检查整个工程中请求路径的正确! 把form的Action改成写死的方式再访问!
[其他解释]
引用:
lz,你的程序我运行过了,就两个地方,改了你就可以运行了。
1.struct.xml文件名写错了,应该是strut.xml
2.action的name不要带写后缀,对应index.jsp里面
3.我改过的strut.xml如下:Plain Text code?12345678910111213<?xml version="1.0" encoding="UTF-8"?……


到底是struts.xml呢?还是strut.xml呢?
[其他解释]
引用:
lz,你的程序我运行过了,就两个地方,改了你就可以运行了。
1.struct.xml文件名写错了,应该是strut.xml
2.action的name不要带写后缀,对应index.jsp里面
3.我改过的strut.xml如下:Plain Text code??12345678910111213<?xml version="1.0" encoding="UTF-8"……



是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">
楼主你用的是struts2.0还是2.3啊,你的struts.xml中写的是2.3的配置啊
[其他解释]
引用:
lz,你的程序我运行过了,就两个地方,改了你就可以运行了。
1.struct.xml文件名写错了,应该是strut.xml
2.action的name不要带写后缀,对应index.jsp里面
3.我改过的strut.xml如下:Plain Text code?12345678910111213<?xml version="1.0" encoding="UTF-8"?……


我刚建工程的时候,可以访问index.jsp,配置好xml文件就不可以访问了,我想知道是不是环境问题?我用tomcat7.0版本,你的可以运行吗?用什么版本的?
[其他解释]
引用:
引用:lz,你的程序我运行过了,就两个地方,改了你就可以运行了。
1.struct.xml文件名写错了,应该是strut.xml
2.action的name不要带写后缀,对应index.jsp里面
3.我改过的strut.xml如下:Plain Text code?12345678910111213<?xml version……


他出现的错误是:
严重: Exception starting filter struts2
java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng
  .filter.StrutsPrepareAndExecuteFilter
[其他解释]
引用:
<?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-2.3.4.1-all
那应该是2.3吧?
[其他解释]
引用:
可以的话,把程序发我qq28205968,我帮你看看。

非常感谢这位大侠,加QQ后帮我远程调试。现在已解决。大致问题及其解决方案如下:
第一个错误:<action name="struts.action" class="org.action.StrutsAction"><result name="success">/welcome.jsp</result>HTTP Status 404 - /struts2/struts.action取名不规范,正常的action的name不要带上.action,因为这是struts2默认的。比如name="xxx", url:/工程名/xxx 或者/工程名/xxx.action。如果一定要这样写,那么就还得在你的<form action="struts.action.action" method="post">第二个错误:java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory 报这个错说明你用的是tomcat7。目前的MyEclipse的内核为Eclipse3.5.* 尚不能提供直接对tomcat 7的支持,最新的Eclipse3.6.*可以直接支持。 解决方法有两个: 一、打开myeclipse,Preferentces->MyEclipse->Servers->Tomcat->Tomcat 6.x ,载入Tomcat7,在"Paths"下,点击“Add JAR/ZIP”,加载tomcat7下的……/bin/tomcat-juli.jar。点击“OK”. 二、可以设置环境变量添加classpath到CATALINE_HOME/bin/tomcat-juli.jar,Tomcat默认启动会自动加载。  classpath=……;%CATALINA_HOME%\bin\tomcat-juli.jar;   第三个错误:ava.net.BindException: Address already in use: JVM_Bind <null>:8009解决方案:端口占用的问题,估计是你启动了多个Tomcat, 端口被自己占用!第四个错误:<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter   </filter-class>不能分两行写,第五个错误:没有导入相应的包,下面是我第一次用build path导入的包,指向了F盘解决方法:把包复制到项目的lib下。在用build path 导入lib 下的包。变成下面的那样的,多了包。而且包没有指向F盘。而且包不重复。第5个错误:他出现的错误是:严重: Exception starting filter struts2java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng   .filter.StrutsPrepareAndExecuteFilter 不能同时部署两个项目。之前因为有写过另一个struts2的项目。这个错误是他的。http://shuimomo.blog.51cto.com/1141396/439438第六个错误:之前我把index.jsp放到WEN-INF下访问不到。你把index.jsp放到webroot下面才能访问到第7个错误:话说,我在地址栏打上地址后,按回车后,它就在myelipse里抛出这个窗口了原因:安装版的tomcat不能用调试模式,直接用run server

热点排行