1.åºäºWEBçJSPç®åç½ç«è´ç©ç³»ç»
2.jspå¦ä½å®ç°ç®åçå¨çº¿è天åè½
åºäºWEBçJSPç®åç½ç«è´ç©ç³»ç»
å ·ä½çåå°ä½ çé®ç®±
å¼åå·¥å ·ï¼eclipse
éç¨ææ¯ï¼j2ee,html工作室源码 struts, hibernate, spring, jsp, jquery, ajax
è¿è¡ç¯å¢ï¼jdk6.0, tomcat6, mysql5
æä½ç³»ç»ï¼linuxæwindows server
ç³»ç»éç¨ç®åæµè¡çsshè½»é级æ¡å ï¼å¹¶éç¨jqueryå®ç°ææajax交äºåè½ï¼æ¯ä¸ä¸ªåè½ä¸°å¯çweb2.0ç«ç¹ã
å®è£ è¿è¡ï¼
1ãå®è£ mysqlæ°æ®åºï¼è¿è¡dbä¸ç建表sqlè¯å¥ï¼åå§åæ°æ®ã
2ãå°é¡¹ç®å¯¼å ¥eclipseä¸ï¼ä¿®æ¹springé ç½®æ件ä¸çæ°æ®åºè¿æ¥åæ°ï¼ä¸ä½ çæ°æ®åºç¯å¢ä¸è´ã
3ãé¢ç½²é¡¹ç®ï¼å¹¶å¯å¨tomcatæå¡å¨ã
4ãå¨æµè§å¨ä¸ï¼è®¿é®é¡¹ç®é¦é¡µhttp://localhost:/voaç½ã
jspå¦ä½å®ç°ç®åçå¨çº¿è天åè½
å åä¸ä¸ªç¨æ·äº¤æµçé¢ åè代ç ä½ å¯ä»¥åè<body>éé¢çå ³é®ä»£ç request.getContextPath();
<head>
<title></title>
</head>
<body>
<form action="servlet/serverMyJsp" method="post">
<textarea rows="" cols="" ><%=application.getAttribute("message") %></textarea><br>
<input type="text" name="message">
<input type="submit" value="åé ">
</form>
</body>
</html>
ååä¸ä¸ªç¨åºæ¥å¤ç客æ·ç交æµä¿¡æ¯å¯ä»¥åèdopost()æ¹æ³éç代ç
package server;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class serverMyJsp extends HttpServlet {
public serverMyJsp() {
super();
}
public void destroy() {
super.destroy();
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
response.setCharacterEncoding("gbk");
request.setCharacterEncoding("gbk");
//String demo=request.getParameter("message");
// String str=new String(demo.getBytes("Iso--1"),"gbk()");
ServletContext sc=this.getServletContext();
String uname=(String) request.getSession().getAttribute("aa");
System.out.println(uname);
String amessage=(String) sc.getAttribute("message");
sc.setAttribute("message", amessage+uname+"说:"+request.getParameter("message")+"\r\n");
response.sendRedirect("../MyJsp.jsp");
}
public void init() throws ServletException {
}
}