Project ‘Struts’ is missing required library:…….
來源:互聯網
上載者:User
今天學習struts 2開發訪問資料庫的登陸程式,項目顯示紅叉,但奇怪的是,項目所有的子檔案都沒錯誤,項目根目錄卻有個紅叉同時eclipse下的problem中出現一個error,提示:Project 'Struts' is missing required library:.......解決方案: 出現這種情況的原因是:在你項目的build path Library中存在重複並且衝突或者地址引用錯誤的jar包,可以這樣來解決: ① 右擊項目------>選Build path------>再選Configure build Path;
② 在右側視窗中選擇Library選項卡;
③ 在下面所列出的jar包中找到帶紅叉mysql-connector-java-5.1.15-bin.jar(一般有問題的jar包都顯示黃色警告或紅色叉號),刪除之;
④ 點擊確定關閉視窗,在eclipse自動重新build workspace後問題就解決了。程式原始碼提供如下:struts.xml檔案:<?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="tutorial" extends="struts-default">
<!-- 使用JDBC串連的使用者登入Action配置 -->
<action name="login" class="login.LoginAction">
<result name="SUCCESS">loginin.jsp</result>
<result name="FAILED">loginout.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"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
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>StrutsDeep</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>login.jsp檔案<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<center>
<h3>使用者登入介面</h3>
<form action="login.action" method ="post">
使用者名稱: <input name="username" type="text"/><br/>
密 碼: <input name="password" type="password"/><br/>
<input name="submit" type ="submit" value="提交"/>
</form>
</center>
</body>
</html>
loginin.jsp檔案<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@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>
<title>Insert title here</title>
</head>
<body>
<center>
<h3>登入成功</h3><br/>
使用者名稱為:<s:property value = "username"></s:property><br/>
密 碼:<s:property value = "password"></s:property>
</center>
</body>
</html>loginout.jsp檔案<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@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>
<title>Insert title here</title>
</head>
<body>
<center>
<h3>登入錯誤</h3><br/>
錯誤:<s:property value = "errinfo"/><br/>
<a href = "login.jsp">返回</a>
</center>
</body>
</html>