Higuys,
我正在用Java运行我的第一个真正的项目
我正在为汽车在线建立一个简单的网站
汽车Seacrh查找工具正在给我带来极大的压力。我已经学会了一些 MVC - struts 使用eclipse来编写代码。
'我正在写的(代码)是关于索引页( index.jsp ),带有几个选择标签(填充下拉列表),当选中时返回'Make;模型;修改....在 View.jsp (结果/视图页面)中。
我有一个 struts.xml 和 web x.ml ,如下所示,但是当我右键单击Project 时,在 Eclipse IDE 中( CarFind SearchTool)>> 导出>> WAR文件我浏览 Tomcat 7.0 / Webapps / ROOT 并保存.war文件/项目。
当我尝试通过URL或Eclipse IDE运行它时,我收到此消息。请允许,任何人都可以帮助我知道如何整理这一切。
HTTP Status 404 - /CarFind_SearchTool/index.jsp
type Status report
message /CarFind_SearchTool/index.jsp
description The requested resource is not available.
Apache Tomcat/7.0.50
但是没有显示控制台消息。
项目MVC :STRUTS2
应用程序:Eclipse IDE,JavaEE,TomCat 7,mysql命令行
项目文件夹: CarFind SearchTool
struts.jar文件从struts 2文件夹中添加.jar文件到项目的WEB-INF / lib
欢迎文件:index.jsp
查看/结果文件 View.jsp
配置文件: struts.xml和web.xml
ActionClass: CarSeacrh.java
数据库 CARS - 表类型
CATALINA C:\ Program Files \ Apache Software Foundation \ Tomcat 7.0
CLASSPATH: C:\ Users \ denis \ workspace \ CarFind SearchTool \ WebContent \ WEB-INF \ lib; C:\ Program Files \ struts-2.3.16.1 \ lib; C:\ Program Files \ MySQL \ Connector J 5.1.28 \ mysql-connector-java-5.1.28-bin; C:\ Program Files \ Apache Software Foundation \ Tomcat 7.0 \ lib \ jsp-api; C:\ glassfish3 \ jdk \ jre \ LIB
JAVA_HOME: C:\ glassfish3 \ jdk
路径: C:\ Program Files \ Common Files \ Microsoft Shared \ Windows Live; C:\ Program Files \ MySQL \ MySQL Server 5.6 \ bin; C:\ glassfish3 \ jdk \ bin; C:\ Program Files \ Apache Software Foundation \ Tomcat 7.0 \ bin; C:\ Program Files \ MySQL \ MySQL Utilities 1.3.6 \; C:\ Program Files \ Windows Live \ Shared
的index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ 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=ISO-8859-1">
<title>Find your favorite car.</title>
</head>
<body>
<h1>All Cars Finance</h1>
<s:form action="hello" namespace="/">
<h4>
<s:select label="Make" headerKey="-1" headerValue="Select Car Make" list="makeList" name="yourCarMake" value="defaultCarMake"/>
</h4>
<h4>
<s:select label="model" headerKey="-1" headerValue="Select Car Model" list="modelList" name="yourCarModel" value="2"/>
</h4>
<h4>
<s:select label="modification" headerKey="-1" headerValue="Select Car Model" list="modificationList" name="yourCarModification" value="2"/>
</h4>
<h4>
<s:select label="engine" headerKey="-1" headerValue="Select Car Engine" list="engineList" name="yourCarEngine" value="2"/>
</h4>
<h4>
<s:select label="color" headerKey="-1" headerValue="Select Car Color" list="colorList" name="yourCarColor" value="2"/>
</h4>
<h4>
<s:select label="bodyType" headerKey="-1" headerValue="Select Car Body Type" list="bodyTypeList" name="yourCarBodyType" value="2"/>
</h4>
<h4>
<s:select label="minPrice" headerKey="-1" headerValue="Select Car Minimum Price" list="minimumPricelist" name="yourCarMinimumPrice" value="2"/>
</h4>
<h4>
<s:select label="model" headerKey="-1" headerValue="Select Car Model" list="modellist" name="yourCarModel" value="2"/></h4>
</s:form>
</body>
</html>
view.jsp的
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ 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=ISO-8859-1">
<title>Car Search Results</title>
</head>
<body>
<h4>
Car Make Search Result is : <s:property value="make"/>
</h4>
<h4>
Car Model Search Result is : <s:property value="model"/>
</h4>
<h4>
Car Modification Search Result is : <s:property value="modification"/>
</h4>
<h4>
Car Engine Search Result is : <s:property value="engine"/>
</h4>
<h4>
Car Color Search Result is : <s:property value="color"/>
</h4>
<h4>
Car Body Type Search Result is : <s:property value="bodyType"/
</h4>
<h4>
Car Minimum Price Search Result is : <s:property value="minPrice"/>
</h4>
<h4>
Car Maximum Price Search Result is : <s:property value="maxPrice"/>
</h4>
<h4>
Car Mileage Search Result is : <s:property value="mileage"/>
</h4>
<h4>
Car Minimum Year Search Result is : <s:property value="minYear"/>
</h4>
<h4>
Car Maximum Year Search Result is : <s:property value="maxYear"/>
</h4>
</body>
</html>
struts.xml中
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLC
"-//Apache Software Foundation//DTD struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="helloworld" extends="struts-default">
<action name="hello"
class="drive.CarSearch"
method="execute">
<result name="success">/View.jsp</result>
</action>
</package>
</struts>
的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_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>CarFind SearchTool</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<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>
</web-app>
CarSearch.java
package drive;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import com.opensymphony.xwork2.ActionSupport;
public class CarSearch extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private String make;
private String model;
private String modification;
private String engine;
private String color;
private String bodyType;
private String minPrice;
private String maxPrice;
private String mileage;
private int minYear;
private int maxYear;
public String execute () {
String ret = NONE;
Connection conn = null;
try {
String URL = "jdbc:mysql://localhost/CARS";
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(URL, "root", "$jademedia247");
String sql = "SELECT make FROM Type WHERE";
sql+=" model = ? AND modification = ? ";
PreparedStatement ps = conn.prepareStatement (sql);
ps.setString(1, model);
ps.setString(2, modification);
ResultSet rs = ps.executeQuery();
while (rs.next()){
make = rs.getString(1);
ret = SUCCESS;
}
} catch (Exception e) {
ret = ERROR;
} finally {
if (conn != null) {
try {
conn.close();
} catch (Exception e) {
}
}
}
return ret;
}
public String getMake() {
return make;
}
public void setMake(String make){
this.make = make;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getModification() {
return modification;
}
public void setModification (String modification) {
this.modification = modification;
}
public String getEngine() {
return engine;
}
public void setEngine (String engine) {
this.engine = engine;
}
public String getColor() {
return color;
}
public void setColor (String color) {
this.color = color;
}
public String getBodyType() {
return bodyType;
}
public void setBodyType(String bodyType) {
this.bodyType = bodyType;
}
public String getMinPrice() {
return minPrice;
}
public void setMinPrice(String minPrice) {
this.minPrice = minPrice;
}
public String getMaxPrice () {
return maxPrice;
}
public void setMaxPrice (String maxPrice) {
this.maxPrice = maxPrice;
}
public String getMileage () {
return mileage;
}
public void setMileage (String mileage) {
this.mileage = mileage ;
}
public int getMinYear() {
return minYear;
}
public void setMinYear(int minYear) {
this.minYear = minYear;
}
public int getMaxYear() {
return maxYear;
}
public void setMaxYear(int maxYear) {
this.maxYear = maxYear;
}
}
C:\Program Files\struts-2.3.16.1\lib
C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\CarFindSearchTool.war
C:\Users\denis\workspace\CarFindSearchTool\WebContent\CarFindSearchTool
C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\CarFindSearchTool.war;C:\Users\denis\workspace\CarFindSearchTool\WebContent\WEB-INF\lib;C:\Program Files\struts-2.3.16.1\lib;C:\Program Files\MySQL\Connector J 5.1.28\mysql-connector-java-5.1.28-bin;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\jsp-api;C:\glassfish3\jdk\jre\lib