问题描述
jsp页面:<%@pagelanguage="java"import="java.util.*,common.DBConnection"pageEncoding="gbk"%><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head></head><body><ahref="test">do</a></body></html>xml:<servlet><description>ThisisthedescriptionofmyJ2EEcomponent</description><display-name>ThisisthedisplaynameofmyJ2EEcomponent</display-name><servlet-name>testServlet</servlet-name><servlet-class>servlet.testServlet</servlet-class></servlet><servlet-mapping><servlet-name>testServlet</servlet-name><url-pattern>/test</url-pattern></servlet-mapping><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list>testServlet放在servlet包下。testServlet代码:publicclasstestServletextendsHttpServlet{@OverrideprotectedvoiddoGet(HttpServletRequestreq,HttpServletResponseresp)throwsServletException,IOException{//TODOAuto-generatedmethodstubPrintWriterm_writer=resp.getWriter();m_writer.println("do");}/***Constructoroftheobject.*/publictestServlet(){super();}}出错提示:message/ownHome_Version_0107_00/test.dodescriptionTherequestedresource(/ownHome_Version_0107_00/test.do)isnotavailable.
解决方案
解决方案二:
href="/test"试试可以么印象里这个要用绝对路径引用
解决方案三:
不行啊,你说的那个是form里面的action,href里面是不用加/吧。
解决方案四:
href="test"没有问题刚动手写了一下没问题可以跳转
解决方案五:
楼上怎么写的?你的可以跳转?我的怎么跳不了呢
解决方案六:
<%@pagelanguage="java"import="java.util.*"pageEncoding="UTF-8"isELIgnored="false"%><%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><basehref="<%=basePath%>"><title>MyJSP'index.jsp'startingpage</title><metahttp-equiv="pragma"content="no-cache"><metahttp-equiv="cache-control"content="no-cache"><metahttp-equiv="expires"content="0"><metahttp-equiv="keywords"content="keyword1,keyword2,keyword3"><metahttp-equiv="description"content="Thisismypage"><!--<linkrel="stylesheet"type="text/css"href="styles.css">--></head><body>ThisismyJSPpage.<br></body></html>
解决方案七:
引用2楼flt2011的回复:
不行啊,你说的那个是form里面的action,href里面是不用加/吧。
我说错了我按你的代码写了一下可以跳转
解决方案八:
<%@pagelanguage="java"import="java.util.*"pageEncoding="UTF-8"isELIgnored="false"%>[color=#FF0000]<%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><basehref="<%=basePath%>">确定路径的,记得加上。
解决方案九:
index.jsp<%@pagelanguage="java"pageEncoding="utf-8"%><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><title>MyJSP'index.jsp'startingpage</title><metahttp-equiv="pragma"content="no-cache"><metahttp-equiv="cache-control"content="no-cache"><metahttp-equiv="expires"content="0"><metahttp-equiv="keywords"content="keyword1,keyword2,keyword3"><metahttp-equiv="description"content="Thisismypage"><!--<linkrel="stylesheet"type="text/css"href="styles.css">--></head><body>hisismyJSPpage.<br><ahref="test">do</a></body></html>
web.xml<?xmlversion="1.0"encoding="UTF-8"?><web-appversion="2.4"xmlns="http://java.sun.com/xml/ns/j2ee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/j2eehttp://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"><servlet><description>ThisisthedescriptionofmyJ2EEcomponent</description><display-name>ThisisthedisplaynameofmyJ2EEcomponent</display-name><servlet-name>Test</servlet-name><servlet-class>Test</servlet-class></servlet><servlet-mapping><servlet-name>Test</servlet-name><url-pattern>/test</url-pattern></servlet-mapping><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list></web-app>
Test.java没有包importjava.io.IOException;importjava.io.PrintWriter;importjavax.servlet.ServletException;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;publicclassTestextendsHttpServlet{publicTest(){super();}publicvoiddestroy(){super.destroy();//Justputs"destroy"stringinlog//Putyourcodehere}publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{response.setContentType("text/html");PrintWriterout=response.getWriter();out.println("<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">");out.println("<HTML>");out.println("<HEAD><TITLE>AServlet</TITLE></HEAD>");out.println("<BODY>");out.print("Thisis");out.print(this.getClass());out.println(",usingtheGETmethod");out.println("</BODY>");out.println("</HTML>");out.flush();out.close();}publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{response.setContentType("text/html");PrintWriterout=response.getWriter();out.println("<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">");out.println("<HTML>");out.println("<HEAD><TITLE>AServlet</TITLE></HEAD>");out.println("<BODY>");out.print("Thisis");out.print(this.getClass());out.println(",usingthePOSTmethod");out.println("</BODY>");out.println("</HTML>");out.flush();out.close();}publicvoidinit()throwsServletException{//Putyourcodehere}}
布署在TOMCAt6中访问的是http://localhost:8088/JD/index.jsp
解决方案十:
我新建了一个可以跳,可是我这个我为什么不能跳呢?全部的xml配置如下:<?xmlversion="1.0"encoding="UTF-8"?><web-appversion="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/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><servlet><description>ThisisthedescriptionofmyJ2EEcomponent</description><display-name>ThisisthedisplaynameofmyJ2EEcomponent</display-name><servlet-name>testServlet</servlet-name><servlet-class>servlet.testServlet</servlet-class></servlet><servlet-mapping><servlet-name>testServlet</servlet-name><url-pattern>/test</url-pattern></servlet-mapping><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list><resource-ref><res-ref-name>jdbc/ownHome</res-ref-name><res-type>javax.sql.DataSource</res-type><res-auth>Container</res-auth></resource-ref></web-app>
解决方案十一:
引用7楼qqcrazyboy的回复:
<%@pagelanguage="java"import="java.util.*"pageEncoding="UTF-8"isELIgnored="false"%>[color=#FF0000]<%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+"://"+reques……
这个加不加都行的,我新建了一个就没加,可以跳
解决方案十二:
你把那个<resource-ref>先删除掉看看跳么?如果跳就是这个的原因再想别的解决方法如果不跳那就不知道了
解决方案十三:
出错提示:message/ownHome_Version_0107_00/test.dodescriptionTherequestedresource(/ownHome_Version_0107_00/test.do)isnotavailable.错误都很详细的写出来了。。路径问题。。/ownHome_Version_0107_00/test.do这是哪来的?你访问test的时候路径是什么?试下/test或者../test
解决方案十四:
404错误就像NullPointerException一样,是最基本最好找的错误了
解决方案十五:
jsp页面:<%@pagelanguage="java"import="java.util.*,common.DBConnection"pageEncoding="gbk"%><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head></head><body><ahref="test.do">do</a></body></html>
解决方案:
是不是你的包名用了servlet这个关键字。。