出现404错误,如下图所示:
没有任何提示,这种情况说明你的Struts配置除了问题,排除问题,测试Struts的跳转问题,步骤:
1、新建一个web project项目
2、新建一个test.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <% 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> This is my JSP page. <br> <a href="test.action">123</a> </body> </html>
3、建立一个action类
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="default" extends="struts-default"> <action name="test" class="org.action.MyAction"> <result name="error">/test.jsp</result> </action> </package> </struts>
4、配置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.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>/index.jsp</welcome-file> </welcome-file-list> <login-config> <auth-method>BASIC</auth-method> </login-config> </web-app>
5、发布项目,打开浏览器,输入http://localhost:8080/项目名/test.jsp,如果跳转成功,说明Struts配置正确了,就在这项目的基础上继续做下去就不会遇到这个404问题了,当然刚开始你要检查Struts那些重要的包有没有导入!
HTTP server 503 问题
解决方法:关闭myEclipse,启动任务管理器,将进程里的javax.exe结束进程,然后重启myEclipse就OK了!
org.hibernate.MappingException: Unknown entity: org.model.Info问题
解决方法:这是将数据存入到数据库表info中遇到的问题,提示说没有找到该实体,说明配置hibernate文件时出现问题,查看hibernate.cfg.xml文件,代码如下:
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <!-- Generated by MyEclipse Hibernate Tools. --> <hibernate-configuration> <session-factory> <property name="dialect">org.hibernate.dialect.SQLServerDialect</property> <property name="connection.url">jdbc:sqlserver://localhost:1433;DatabaseName=J2EE1</property> <property name="connection.username">sa</property> <property name="connection.password">123456</property> <property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property> <property name="myeclipse.connection.profile">SQL</property> </session-factory> </hibernate-configuration>
仔细观察里面的代码,发现并没有把表info的资源加入进去,所以要加入<mapping resource="org/model/Info.hbm.xml" />这句代码,即:
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <!-- Generated by MyEclipse Hibernate Tools. --> <hibernate-configuration> <session-factory> <property name="dialect">org.hibernate.dialect.SQLServerDialect</property> <property name="connection.url">jdbc:sqlserver://localhost:1433;DatabaseName=J2EE1</property> <property name="connection.username">sa</property> <property name="connection.password">123456</property> <property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property> <property name="myeclipse.connection.profile">SQL</property> <mapping resource="org/model/Info.hbm.xml" /> </session-factory> </hibernate-configuration>
这样就会发现数据能存储到数据库表中了,问题解决!