- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 eclipse 中创建了一个小的“动态 Web 项目”,并尝试显示/编辑/创建和删除我的数据库对象。 tomcat 服务器运行。但是我收到 HTTP 状态 404 错误:请求的资源 (/TestDynWeb/) 不可用 (http://localhost:8010/TestDynWeb)。我想显示我所有的代码文件。也许您知道出了什么问题。
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_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>TestDynWeb</display-name>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<jsp-config>
<taglib>
<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location>/WebContent/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-nested.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>
struts-config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd" >
<struts-config>
<!-- Form Bean Definitions -->
<form-beans>
<form-bean name="ListForm" type="list.forms.ListForm"/>
</form-beans>
<!-- Action Mapping Definitions -->
<action-mappings>
<action path="/showlist" type="list.misc.ShowList" validate="false" scope="session">
<forward name="success" path="/jsp/listScreen.jsp"/>
</action>
<!-- Example of Struts Dispatch Action : has the extra attribute parameter-->
<action path="/listaction" type="list.actions.ListAction" parameter="actionMethod" name="ListForm"
validate="false" scope="session">
<forward name="addObject" path="/jsp/createScreen.jsp"/>
<forward name="editObject" path="/jsp/editScreen.jsp"/>
</action>
</action-mappings>
</struts-config>
listScreen.jsp
<%@ page import="java.util.HashMap"%>
<%@ page import="java.util.Map"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import="java.util.Iterator"%>
<html>
<body>
<b>Available Data Base Objects</b>
<form name="listform" action="/listaction.do">
<table style="background-color: #82CAFA;">
<tr style="color: white;">
<th> </th>
<th>Object ID</th>
<th>Object Name</th>
<th>Person ID</th>
<th>Date (Dev)</th>
<th>Version (Dev)</th>
</tr>
<%
List objectsList = (ArrayList) request.getAttribute("objectsList");
Iterator itr = objectsList.iterator();
while (itr.hasNext()) {
Map map = (HashMap) itr.next();
%>
<tr>
<td><input type="radio" name="dboId"
value='<%=map.get("dboId")%>'
onclick="javascript:enableEditDelete();"></td>
<td><%=map.get("dboID")%></td>
<td><%=map.get("dboDevName")%></td>
<td><%=map.get("personId")%></td>
<td><%=map.get("changedByTimestampDEV")%></td>
<td><%=map.get("releaseVersionDev")%></td>
</tr>
<%
}
%>
</table>
</p>
<p>
<table>
<tr>
<td><input type="submit" name="actionMethod" id="editbutton"
value="Edit Object" disabled="true" style="color: black;" /></td>
<td><input type="submit" name="actionMethod" id="deletebutton"
value="Delete Object" disabled="true" onclick="return checkDelete();" style="color: black;" /></td>
</tr>
</table>
</form>
</p>
<script>
function checkDelete() {
return confirm("Are u sure to delete this object..?");
}
function enableEditDelete() {
document.getElementById('editbutton').disabled = false;
document.getElementById('deletebutton').disabled = false;
}
</script>
</body>
</html>
editScreen.jsp
<b>Edit Object</b>
<html:form>
<p>
</p><table style="background-color: #82CAFA;">
<tr style="color: white;">
<td>Object ID</td>
<td><html:text property="dboId" disabled="true"/></td>
</tr>
<tr style="color: white;">
<td>Object Name</td>
<td><html:text property="dboDevName"/></td>
</tr>
<tr style="color: white;">
<td>Person ID</td>
<td><html:text property="personId"/></td>
</tr>
<tr style="color: white;">
<td>Date (Dev)</td>
<td><html:text property="changedByTimestampDEV"/></td>
</tr>
<tr style="color: white;">
<td>Version (Dev</td>
<td><html:text property="releaseVersionDev"/></td>
</tr>
</table>
<p/>
<p>
</p><table>
<tr>
<td><input type="submit" name="actionMethod" value="Save Object" style="color: black;"/></td>
</tr>
</table>
</html:form>
<p/>
createScreen.jsp
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<html>
<body>
<b>Add Object</b>
<html:form>
<table style="background-color: #82CAFA;">
<tr>
<td>Object ID</td>
<td><html:text property="dboId" disabled="true" /></td>
</tr>
<tr>
<td>Object Name</td>
<td><html:text property="dboDevName" /></td>
</tr>
<tr>
<td>Person ID</td>
<td><html:text property="personId" /></td>
</tr>
<tr>
<td>Date (Dev)</td>
<td><html:text property="changedByTimestampDEV" /></td>
</tr>
<tr>
<td>Version (Dev</td>
<td><html:text property="releaseVersionDev" /></td>
</tr>
</table>
</p>
<p>
<table>
<tr>
<td><input type="submit" name="actionMethod" value="Add Object" /></td>
</tr>
</table>
</html:form>
</p>
</body>
</html>
appContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.1.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver" />
<property name="url"
value="jdbc:jtds:sqlserver://localhost:1433;databaseName=NARTrackingDB" />
<property name="username" value="abc" />
<property name="password" value="xyz" />
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="objDao" class="tracking.dao.DboDao">
<property name="transactionManager" ref="transactionManager" />
</bean>
</beans>
package tracking.dao;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import javax.sql.DataSource;
import org.objectweb.asm.Type;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import tracking.bean.DboBean;
public class DboDao {
private DataSourceTransactionManager transactionManager;
private JdbcTemplate jdbcTemplate;
private DataSource dataSource; // either use @Autowire or provide xml config
//private String dboDevName;
public DboDao() {
// TODO Auto-generated constructor stub
super();
}
public DboBean read(final int dboId) {//String dboId
// TODO Auto-generated method stub
String sql = "SELECT * FROM da_tracking "
+ "WHERE ins_ID = " + dboId;
final Object[] params = new Object[] {};
//Creating object being queried
final DboBean dboBean = new DboBean();
//Process query Results
jdbcTemplate.query(sql, params, new RowCallbackHandler(){
public void processRow(ResultSet rs) throws SQLException{
dboBean.setDboId(rs.getString("ins_ID"));
dboBean.setDboDevName(rs.getString("ins_name"));
}
});
return dboBean;//returns queried objects
}
public int save(DboBean record ) {
// TODO Auto-generated method stub
String sql = "UPDATE da_tracking"
+ " SET ins_name= ?,"
+ " ins_dev_scripted = ?"
+ " WHERE ins_ID = ?" ;
Object[] params = new Object[] {
record.getDboDevName(),
record.getDevScripted(),
record.getDboId()
};
int[] types = new int[]{
Types.VARCHAR,
Types.BIT,
Types.INTEGER};
return jdbcTemplate.update(sql, params, types);
}
public int createInstance(DboBean record) {
// TODO Auto-generated method stub
String sql = "INSERT INTO da_tracking"
+ "(ins_ID,ins_name,ins_deployed_to_uat, ins_dev_status,ins_dev_scripted,ins_dev_changed_by_timestamp"
+ "change_details,db_owner_ID,type_ID,person_ID,changeType_ID,ins_uat_changed_by_timestamp,release_version_dev"
+ "release_version_uat) VALUES"
+ "( ?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
Object[] params = new Object[] {
record.getDboId(),record.getDboDevName(),record.getDeployedToUAT(),record.getDevStatus(),record.getDevScripted(),
record.getChangedByTimestampDEV(),record.getChangeDetails(),record.getDbOwner(),record.getTypeId(),record.getPersonId(),
record.getChangedByTimestampUAT(),record.getReleaseVersionDev(),record.getReleaseVersionUat()
};
int[] types = new int[]{
Types.INTEGER, Types.VARCHAR, Types.BIT, Types.INTEGER, Types.BIT,
Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER,
Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR
};
return jdbcTemplate.update(sql, params, types);
}
public void delete(String dboId) {
// TODO Auto-generated method stub
String sql = "DELETE FROM da_tracking "
+ "WHERE ins_ID = " + dboId;
Object[] params = new Object[] {};
//Process query Results
jdbcTemplate.update(sql, params);
}
public JdbcTemplate getJdbcTemplate() {
return jdbcTemplate;
}
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
public DataSource getDataSource() {
return dataSource;
}
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}
//Spring setter injector used
public void setTransactionManager(DataSourceTransactionManager transactionManager){
this.transactionManager = transactionManager;
DataSource datatSource = transactionManager.getDataSource();
jdbcTemplate = new JdbcTemplate(datatSource);
}
}
--DBOBean.java 包括 getters 和 setters--这里不需要显示
ShowList.java:
package list.misc;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.Action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ShowList extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
System.out.println("Show Objects List");
ListObjects l = ListObjects.getInstance();
request.setAttribute("objectsList", l.getObjectList());
return mapping.findForward("success");
}
}
ListObjects:
package list.misc;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Set;
public class ListObjects {
int objectIdCount = 1000;
Map<Integer, StoreObject> objectMap = new HashMap<Integer, StoreObject>();
private static ListObjects objects = null;
private ListObjects() {
}
public static ListObjects getInstance() {
if (objects == null) {
objects = new ListObjects();
}
return objects;
}
public void storeObject(String dboDevName, int personId, String changedByTimestampDEV, String releaseVersionDev) {
StoreObject so = new StoreObject();
objectIdCount++;
so.addObject(objectIdCount, dboDevName, personId, changedByTimestampDEV, releaseVersionDev);
objectMap.put(objectIdCount, so);
}
public void updateObject(int dboId, String dboDevName, int personId, String changedByTimestampDEV, String releaseVersionDev) {
StoreObject so = objectMap.get(dboId);
so.updateObject(dboId, dboDevName, personId, changedByTimestampDEV, releaseVersionDev );
}
public Map searchObject(int dboId) {
return objectMap.get(dboId).getObject();
}
public void deleteObject(int dboIds) {
objectMap.remove(dboIds);
}
// Inner Class used to persist the app data ie. object details.
public class StoreObject {
private String dboDevName;
private String changeDetails;
private String changedByTimestampDEV;
String releaseVersionDev;
private int personId;
private int objectIdCount;
private int dboId;
StoreObject() {
}
public void addObject(int objectIdCount, String dboDevName, int personId, String changedByTimestampDEV, String releaseVersionDev) {
this.objectIdCount = objectIdCount;
this.dboDevName = dboDevName;
this.personId = personId;
this.changedByTimestampDEV = changedByTimestampDEV;
this.releaseVersionDev = releaseVersionDev;
}
public void updateObject(int dboId, String dboDevName, int personId, String changedByTimestampDEV, String releaseVersionDev) {
this.dboId = dboId;
this.dboDevName = dboDevName;
this.personId = personId;
this.changedByTimestampDEV = changedByTimestampDEV;
this.releaseVersionDev = releaseVersionDev;
}
@SuppressWarnings("unchecked")
public Map getObject() {
Map objects = new HashMap();
objects.put("objectIdCount", this.objectIdCount);
objects.put("dboDevName", this.dboDevName);
objects.put("personId", this.personId);
objects.put("changedByTimestampDEV", this.changedByTimestampDEV);
objects.put("releaseVersionDev", this.releaseVersionDev);
return objects;
}
}
public List getObjectList() {
List objectsList = new ArrayList();
Set s = objectMap.keySet();
Iterator itr = s.iterator();
while (itr.hasNext()) {
objectsList.add(objectMap.get((Integer) itr.next()).getObject());
}
return objectsList;
}
}
--ListForm.java 包含 getter 和 setter -- 此处不需要。
ListAction.java:
package list.actions;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.apache.struts.actions.DispatchAction;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
import list.forms.ListForm;
import list.misc.ListObjects;
public class ListAction extends DispatchAction {
public ActionForward AddObj(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
System.out.println("Add Object Page");
return mapping.findForward("addObj");
}
public ActionForward EditObj(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
System.out.println("Edit Object Page");
int dboId = Integer.parseInt(request.getParameter("dboId"));
ListObjects l = ListObjects.getInstance();
@SuppressWarnings("rawtypes")
Map objMap = l.searchObject(dboId);
// Used form bean class methods to fill the form input elements with
// selected object values.
ListForm lf = (ListForm) form;
lf.setDboId((Integer) objMap.get("dboId"));
lf.setDboDevName(objMap.get("dboDevName").toString());
lf.setTypeId((Integer) objMap.get("typeId"));
lf.setChangeDetails(objMap.get("changeDetails").toString());
lf.setChangeType((Integer) objMap.get("changeType"));
lf.setDevScripted((Boolean) objMap.get("devScripted"));
lf.setPersonId((Integer) objMap.get("personId"));
lf.setChangedByTimestampDEV(objMap.get("changedByTimestampDEV").toString());
lf.setChangedByTimestampUAT(objMap.get("changedByTimestampUAT").toString());
lf.setReleaseVersionDev(objMap.get("releaseVersionDev").toString());
lf.setReleaseVersionUat(objMap.get("releaseVersionUat").toString());
return mapping.findForward("addObject");
}
public ActionForward SaveObj(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
System.out.println("Save Object");
// Used form bean class methods to get the value of form input elements.
ListForm lf = (ListForm) form;
int dbOwner = lf.getDbOwner();
String dboDevName = lf.getDboDevName();
int typeId = lf.getTypeId();
String changeDetails = lf.getChangeDetails();
int changeType = lf.getChangeType();
Boolean devScripted = lf.isDevScripted();
int personId = lf.getPersonId();
String changedByTimestampDEV = lf.getChangedByTimestampDEV();
String changedByTimestampUAT = lf.getChangedByTimestampUAT();
String releaseVersionDev = lf.getReleaseVersionDev();
String releaseVersionUat = lf.getReleaseVersionUat();
ListObjects l = ListObjects.getInstance();
l.storeObject(dboDevName, personId, changedByTimestampDEV, releaseVersionDev);
return new ActionForward("/showlist.do", true);
}
public ActionForward CreateObj(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
System.out.println("Update Object");
ListForm lf = (ListForm) form;
int dboId = lf.getDboId();
String dboDevName = lf.getDboDevName();
int typeId = lf.getTypeId();
String changeDetails = lf.getChangeDetails();
int changeType = lf.getChangeType();
Boolean devScripted = lf.isDevScripted();
int personId = lf.getPersonId();
String changedByTimestampDEV = lf.getChangedByTimestampDEV();
String changedByTimestampUAT = lf.getChangedByTimestampUAT();
String releaseVersionDev = lf.getReleaseVersionDev();
String releaseVersionUat = lf.getReleaseVersionUat();
ListObjects l = ListObjects.getInstance();
l.updateObject(dboId, dboDevName, personId, changedByTimestampDEV, releaseVersionDev);
return new ActionForward("/showlist.do", true);
}
public ActionForward DeleteObject(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
System.out.println("Delete Object");
int dboId = Integer.parseInt(request.getParameter("dboId"));
ListObjects lo = ListObjects.getInstance();
lo.deleteObject(dboId);
return new ActionForward("/showlist.do", true);
}
}
非常感谢您的帮助。
最佳答案
可能您还没有在 Tomcat 服务器上部署您的应用程序。您需要在“服务器” View 中右键单击服务器,然后按“添加和删除”,然后将您的项目添加到服务器。
关于java - HTTP 404 请求的资源 (//) 不可用 - Tomcat 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12447750/
我正在尝试从该网站抓取历史天气数据: http://www.hko.gov.hk/cis/dailyExtract_uc.htm?y=2016&m=1 在阅读了 AJAX 调用后,我发现请求数据的正确
我有两个 postman 请求 x,y,它们命中了两个不同的休息 api X,Y 中的端点。 x 会给我一个身份验证 token ,这是发出 y 请求所必需的。如何在请求 y 中发出请求 x ?也就是
我使用请求库通过 API 与其他服务器进行通信。但现在我需要同时发送多个(10 个或更多)POST 请求,并且只有在所有响应都正确的情况下才能进一步前进。通常语法看起来有点像这样: var optio
背景:当用户单击按钮时,其类会在class1和class2之间切换,并且此数据是通过 AJAX 提交。为了确认此数据已保存,服务器使用 js 进行响应(更新按钮 HTML)。 问题:如果用户点击按钮的
我正在将 Node.js 中的请求库用于 Google 的文本转语音 API。我想打印出正在发送的请求,如 python example . 这是我的代码: const request = requi
我经常使用requests。最近我发现还有一个 requests2 和即将到来的 requests3 虽然有一个 page其中简要提到了 requests3 中的内容,我一直无法确定 requests
我正在尝试将图像发送到我的 API,然后从中获取结果。例如,我使用发送一个 bmp 图像文件 file = {"img": open("img.bmp)} r = requests.post(url,
我发现 Google Cloud 确保移出其物理环境的任何请求都经过强制加密,请参阅(虚拟机到虚拟机标题下的第 6 页)this link Azure(和 AWS)是否遵循类似的程序?如果有人能给我指
我有一个 ASP.NET MVC 应用程序,我正在尝试在 javascript 函数中使用 jQuery 来创建一系列操作。该函数由三部分组成。 我想做的是:如果满足某些条件,那么我想执行同步 jQu
我找不到如何执行 get http 请求,所以我希望你们能帮助我。 这个想法是从外部url(例如 https://api.twitter.com/1.1/search/tweets.json?q=tw
我的应用只需要使用“READ_SMS”权限。我的问题是,在 Android 6.0 上,当我需要使用新的权限系统时,它会要求用户“发送和查看短信”。 这是我的代码: ActivityCompat.re
我的前端代码: { this.searchInput = input; }}/> 搜索 // search method: const baseUrl = 'http://localho
我有一个由 AJAX 和 C# 应用程序使用的 WCF 服务, 我需要通过 HTTP 请求 header 发送一个参数。 在我的 AJAX 上,我添加了以下内容并且它有效: $.ajax({
我正在尝试了解如何使用 promises 编写代码。请检查我的代码。这样对吗? Node.js + 请求: request(url, function (error, response, body)
如果失败(除 HTTP 200 之外的任何响应代码),我需要重试发送 GWT RPC 请求。原因很复杂,所以我不会详细说明。到目前为止,我在同一个地方处理所有请求响应,如下所示: // We
当用户单击提交按钮时,我希望提交表单。然而,就在这种情况发生之前,我希望弹出一个窗口并让他们填写一些数据。一旦他们执行此操作并关闭该子窗口,我希望发出 POST 请求。 这可能吗?如果可能的话如何?我
像 Facebook 这样的网站使用“延迟”加载 js。当你必须考虑到我有一台服务器,流量很大时。 我很感兴趣 - 哪一个更好? 当我一次执行更多 HTTP 请求时 - 页面加载速度较慢(由于限制(一
Servlet 容器是否创建 ServletRequest 和 Response 对象或 Http 对象?如果是ServletRequest,谁在调用服务方法之前将其转换为HttpServletReq
这是维基百科文章的摘录: In contrast to the GET request method where only a URL and headers are sent to the serv
我有一个循环,每次循环时都会发出 HTTP post 请求。 for(let i = 1; i console.log("succes at " + i), error => con
我是一名优秀的程序员,十分优秀!