为啥从Jsp页面跳转不到servlet页面

为啥从Jsp页面跳转不到servlet页面

为什么从Jsp页面跳转不到servlet页面

我的工程名是MyBlogOnline然后在src目录下有一个包com.myblog.Servlet,在这个包里有一个PhotoServlet页面,在WebRoot根目录中有一个admin的文件夹,在这个文件里面还有一个photo文件夹,然后在这个photo文件夹里有一个PhotoUpload.jsp页面。现在就是想通过点击提交跳转到servlet。(在台式电脑那边的eclipse的环境能执行但是在我自己的笔记本电脑那里就是执行不了)代码如下:

servlet代码:

package com.myblog.servlet;

import java.io.IOException;

import java.io.PrintWriter;

import java.util.ArrayList;

import javax.servlet.RequestDispatcher;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import com.jspsmart.upload.File;

import com.jspsmart.upload.Request;

import com.jspsmart.upload.SmartUpload;

import com.jspsmart.upload.SmartUploadException;

import com.myblog.dao.PhotoDao;

public class PhotoServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

doPost(request,response);

}

//上传图片

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

String href=””;

SmartUpload su=new SmartUpload();

su.initialize(this.getServletConfig(),request,response);

//设置需上传的图片的最大大小2M

su.setMaxFileSize(2*1024*1024);

//设置只允许上传图片

su.setAllowedFilesList(“jpg,gif,bmp”);

try {

//上传文件

su.upload();

int count=su.save(“/front/photo/pic”);

System.out.println(count);

//获取照片描述信息

//在使用jspSmartUpload组件时,内置对象request不能用了

//而是需要使用本组件自带的request来产生一个对象

Request request1=su.getRequest();

String info=request1.getParameter(“info”);

System.out.print(info);

//获取上传的文件

File file=su.getFiles().getFile(0);

if(!file.isMissing()){

String filename=”/front/photo/pic/”+System.currentTimeMillis()+file.getFileExt();

file.saveAs(filename,File.SAVEAS_VIRTUAL);

}

} catch (SmartUploadException e) {

e.printStackTrace();

}

}

}

jsp代码:

<%@ page language=”java” import=”java.util.*” pageEncoding=”gb2312″%>

<html>

  <head>

  <title>我的博客后台-上传照片</title>

  <link rel=”stylesheet” type=”text/css” href=”styles.css”>

  </head>

  

  <body>

  <center>

  <table width=”777″ border=”0″ cellspacing=”0″ cellpadding=”0″ bgcolor=”#FFFFFF” style=”word-break:break-all;” >

  <tr><td colspan=”2″><jsp:include page=”../view/AdminTop.jsp”/></td></tr>

  <tr>

  <td><jsp:include page=”../view/AdminLeft.jsp”/></td>

  <td align=”center” valign=”top”>

  <form action=”PhotoServlet” method=”post” enctype=”multipart/form-data”>

  <table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”8″>

  <tr height=”60″><td colspan=”2″>【上传照片】</td></tr>

  <tr>

  <td align=”center”>选择照片:</td>

  <td><input type=”file” name=”path” size=”50″></td>

  </tr>

  <tr>

 

为啥从Jsp页面跳转不到servlet页面

相关文章:

你感兴趣的文章:

标签云: