Soubudy Soubudy
关注数: 28 粉丝数: 82 发帖数: 3,110 关注贴吧数: 40
求助`。`JSP代码以上。`。。。。。。。。。 -------------------------查询连接``。package DBcon;import java.sql.*;import java.util.ArrayList;public class Insert { private static CreateDBcon con=new CreateDBcon(); private static Connection dbconn=null; private static PreparedStatement ps=null; private static ResultSet rs=null; public Insert() { } public void pst(String sql){ try { dbconn=con.createDBcon(); ps=dbconn.prepareStatement(sql); } catch (Exception ex) { ex.printStackTrace(); } } public void insertOneTitle(String onetitle){ try { String sql="insert into oneTitle(titleName ) values('"+onetitle+"')"; this.pst(sql); ps.executeUpdate(); this.close(); } catch (Exception ex) { ex.printStackTrace(); } } public ArrayList add(){ ArrayList add=new ArrayList(); return add; } public void SelectOneTitle(){ try { String sql="Select titleName from oneTitle"; this.pst(sql); rs=ps.executeQuery(); while (rs.next()) { this.add().add(rs.getString(1)); } } catch (Exception ex) { } } private void close(){ try { if (ps!=null) { ps.close(); } if (dbconn!=null) { dbconn.close(); } } catch (Exception ex) { } }}------------------取的值``````````package TitleServlet;import javax.servlet.*;import javax.servlet.http.*;import java.io.*;import java.util.*;import DBcon.Insert;public class TwoTitleServlet extends HttpServlet { private static Insert select=new Insert(); private static final String CONTENT_TYPE = "text/html; charset=GBK"; //Initialize global variables public void init() throws ServletException { } //Process the HTTP Get request public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(CONTENT_TYPE); PrintWriter out = response.getWriter(); HttpSession session=request.getSession(); ArrayList add=select.add(); if (add.size()>0) { int i=0; for (; i "); out.print("alert('没有一级标题!')"); out.close(); } //Clean up resources
急!!为会么用Servlet发送邮件到网络邮箱不行?? package project;import javax.servlet.*;import javax.servlet.http.*;import java.io.*;import java.util.*;import javax.mail.Session;import javax.mail.internet.MimeMessage;import javax.mail.internet.InternetAddress;import javax.mail.internet.MimeMessage.RecipientType;import javax.mail.Transport;public class EmailServlet extends HttpServlet { DBcon db=new DBcon(); private static final String CONTENT_TYPE = "text/html; charset=GBK"; private String topwd; //Initialize global variables public void init() throws ServletException { } //Process the HTTP Get request public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(CONTENT_TYPE); PrintWriter out = response.getWriter(); String userName=request.getParameter("txtName"); String toemail=request.getParameter("txtEmail"); String host=request.getParameter("smtp.163.com"); String from=request.getParameter("[email protected]"); topwd=db.getPwd(userName,toemail); out.print(topwd+userName+toemail); Properties props=System.getProperties(); try { if (userName.equals("")||toemail.equals("")){ this.noNull(out); } else { if (topwd!=null) { props.put("mail.transport.protocol","smtp"); props.put("mail.smtp.host",host); props.put("mail.smtp.host","25"); Session session=Session.getInstance(props,null); MimeMessage msg=new MimeMessage(session); msg.setFrom(new InternetAddress(from)); msg.addRecipient(RecipientType.TO,new InternetAddress(toemail)); msg.setSubject("this is a test"); msg.setText("用户名为:"+userName+"密码为:"+topwd); Transport.send(msg); this.ok(out); } else { this.noUser(out); } } } catch (Exception ex) { } out.close(); } //Process the HTTP Post request public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } public void noNull(PrintWriter out){ out.print(" alert('输入有误不能为空!')"); } public void noUser(PrintWriter out){ out.print(" alert('用户不存在!')"); } public void ok(PrintWriter out){ out.print("密码已经发送到你的邮箱成功!"); out.print("http://tieba.baidu.com/mo/q/checkurl?url=lginemail.html&urlrefer=dacdacb1ecb74308bafbaf88098c5a27"); } //Clean up resources public void destroy() { }}
我的JSP配置不能用。这是怎样回事请高手帮一下,,谢谢。 一、开发环境配置 第一步:下载j2sdk和tomcat:到sun官方站(http://java.sun.com/j2se/1.5.0/download.jsp)下载j2sdk,注意下载版本为Windows Offline Installation的SDK,同时最好下载J2SE 1.5.0 Documentation,然后到tomcat官方站点(http://jakarta.apache.org/site/downloads/downloads_tomcat-5.cgi)下载tomcat(下载最新5.5.9版本的tomcat); 第二步:安装和配置你的j2sdk和tomcat:执行j2sdk和tomcat的安装程序,然后按默认设置进行安装即可。 1.安装j2sdk以后,需要配置一下环境变量,在我的电脑->属性->高级->环境变量->系统变量中添加以下环境变量(假定你的j2sdk安装在c:\j2sdk1.5.0): JAVA_HOME=c:\j2sdk1.5.0 classpath=.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;(.;一定不能少,因为它代表当前路径) path=%JAVA_HOME%\bin 接着可以写一个简单的java程序来测试J2SDK是否已安装成功: public class Test{ public static void main(String args[]){ System.out.println("This is a test program."); } } 将上面的这段程序保存为文件名为Test.java的文件。 然后打开命令提示符窗口,cd到你的Test.java所在目录,然后键入下面的命令 javac Test.java java Test 此时如果看到打印出来This is a test program.的话说明安装成功了,如果没有打印出这句话,你需要仔细检查一下你的配置情况。 2.安装Tomcat后,在我的电脑->属性->高级->环境变量->系统变量中添加以下环境变量(假定你的tomcat安装在c:\tomcat): CATALINA_HOME=c:\tomcat CATALINA_BASE=c:\tomcat 然后修改环境变量中的classpath,把tomat安装目录下的common\lib下的(可以根据实际追加)servlet.jar追加到classpath中去,修改后的classpath如下: classpath=.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;%CATALINA_HOME%\common\lib\servlet.jar; 接着可以启动tomcat,在IE中访问http://localhost:8080,如果看到tomcat的欢迎页面的话说明安装成功了。 第三步:建立自己的jsp app目录 1.到Tomcat的安装目录的webapps目录,可以看到ROOT,examples, tomcat-docs之类Tomcat自带的的目录; 2.在webapps目录下新建一个目录,起名叫myapp; 3.myapp下新建一个目录WEB-INF,注意,目录名称是区分大小写的; 4.WEB-INF下新建一个文件web.xml,内容如下: My Web Application A application for test. 5.在myapp下新建一个测试的jsp页面,文件名为index.jsp,文件内容如下: Now time is: <%=new java.util.Date()%> 6.重启Tomcat 7.打开浏览器,输入http://localhost:8080/myapp/index.jsp 看到当前时间的话说明就成功了。 可以是我看到的是:HTTP Status 404 - /myapp/index.jsp--------------------------------------------------------------------------------type Status reportmessage /myapp/index.jspdescription The requested resource (/myapp/index.jsp) is not available.--------------------------------------------------------------------------------Apache Tomcat/6.0.10这是怎样回事啊。???/?
1 下一页