servleté 置以å跳转
jspä¸è·³è½¬servletæ¶åçç¸å¯¹è·¯å¾é®é¢ãå ç项ç®ç®å½ç»æ
jsp代ç WebContent/admin/login.jspï¼
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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>管çåç»å½</title>
</head>
<body>
<form action="../adminServlet?action=login" method="post">
<h1>管çåç»å½</h1>
<label>è´¦å·ï¼</label> <input type="text" name="username" /> <br> <label>å¯ç ï¼<%=basePath%></label>
<input type="password" name="password" /><br> <input
type="submit" value="ç»å½" />
<div>${requestScope.error}</div>
</form>
</body>
</html>
ä¸è¬æ åµä¸, æ们å¨é¡µé¢ä¸ä½¿ç¨èµæº(JSP. Servletå¨æèµæº, å¾ç, css js çéæèµæº)æ¶, é½ä½¿ç¨ç¸å¯¹è·¯å¾.
å¨formçactionå±æ§ä¸ï¼æ们è¿éç±äºlogin.jspå¨adminæ件夹ä¸ï¼æ以æ¯
<form action="../adminServlet?action=login" method="post">
é£ä¸ºä»ä¹è¿æ ·åï¼
actionä¸å½¢å¦: adminServlet?action=login, æè ./å¼å§ 以å½å页é¢ç访é®è·¯å¾ä½ä¸ºæ ¹è·¯å¾
http://localhost:8080/muke/admin/login.jsp->é»è®¤æ ¹è·¯å¾ï¼http://localhost:8080/muke/admin/
请æ±è·¯å¾: http://localhost:8080/muke/admin/adminServlet?action=login
å½¢å¦: /adminServlet?action=login, 以å½åæå¡å¨çæ ¹è·¯å¾ä½ä¸ºç¸å¯¹è·¯å¾çæ ¹è·¯å¾
http://localhost:8080/muke/admin/login.jsp->é»è®¤æ ¹è·¯å¾:http://localhost:8080/
请æ±: http://localhost:8080/adminServlet?action=login
å½¢å¦:.. /adminServlet?action=login, 以å½åè·¯å¾çç¶è·¯å¾ä½ä¸ºæ ¹è·¯å¾
http://localhost:8080/muke/login.jsp->é»è®¤æ ¹è·¯å¾:http://localhost:8080/muke
http://localhost:8080/muke/adminServlet?action=login
servletæ们ç¨æ³¨è§£çæ¹æ³
å®çè·¯å¾ï¼è¿æ ·æ¯å¨http://localhost/8080/muke/adminServlet.æ以ä¸ç®¡æ们jspå¨ä»ä¹å°æ¹ï¼æ们åªè¦æ ¹æ®jspçç¸å¯¹è·¯å¾å¹é å°http://localhost/8080/muke/ä¸ï¼å°±å¯ä»¥è·³è½¬å°servletï¼å°±æ¯jsp请æ±è·¯å¾ä¸º
http://localhost:8080/muke/adminServlet?action=login
ã********************************************************************************************ã
å ¶å®æ们å¯ä»¥å¨ç¨è¿æ ·çæ¹æ³ï¼ä½¿å¾jspä¸actionå°±çäºaction=âadminServletâ.èä¸ç¨å /æè ./æè ../çï¼å°±æ¯æ们ä¸ç®¡jspå¨åªéï¼ææjspè·¯å¾é½æ¹ä¸ºç»å¯¹è·¯å¾ã
å³é®æ°å»ºjsp页é¢ï¼
ç¶ånextï¼ä¸è¦ç¹finishï¼æ们æ¥é ç½®ä¸æ¨¡æ¿
ç¹å»è¿éçjsp templatesï¼ç¶å
éä¸è¿ä¸é¡¹ï¼ç¹å»editï¼ç¼è¾æ¨¡æ¿
<%@ page language="java" contentType="text/html; charset=${encoding}"
pageEncoding="${encoding}"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!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=UTF-8">
<base href="<%=basePath %>">
<title>Insert title here</title>
</head>
<body>
${cursor}
</body>
</html>
æè¿ä¸ªç²è¿å»ï¼è¦çæ以åçææãæ们æ¥è¯´ä¸ä¸ã
<%
String path = request.getContextPath();##è·å¾å½åç®å½åå¦è¿éæ¯muke
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
request.getScheme()ï¼åè®®åï¼httpã
request.getServerName()ï¼æå¡åï¼localhostã
request.getServerPort()ï¼ç«¯å£å·ï¼8080ã
pathï¼ç®å½åï¼mukeã
<base href="<%=basePath %>">ï¼ç¨baseæ ç¾ï¼è®¾ç½®è¯¥jspæ ¹ç®å½ä¸ºbasePathéé¢çå¼ï¼å³http://localhost:8080/muke
è¿æ ·æ们å¨è·³è½¬æ¶åï¼forméçactionå°±ä¸ç¨è´¹å²è·¯å¾äºï¼ç´æ¥è¿æ ·ï¼
上一篇: C语言_数组知识总结
下一篇: 求100以内质数或者更多
推荐阅读
-
servleté 置以å跳转
-
servlet 页面跳转方法总结(1)
-
Eclipse将第三方jar包插件和项目一起发布到web容器中 博客分类: eclipse eclipseweblogic.servlet.jsp.CompilationExceptionjsp编译问题
-
Eclipse将第三方jar包插件和项目一起发布到web容器中 博客分类: eclipse eclipseweblogic.servlet.jsp.CompilationExceptionjsp编译问题
-
Servlet下页面跳转方式
-
Servlet跳转之转向(Forward)
-
Servlet 之间的跳转+数据传递
-
jsp跳转到servlet找不到路径解决
-
两个servlet之间的跳转
-
servlet跳转