我做了一个servlet为什么访问这个servlet的时候会下载这个文件
下面是html<html><head><title>ASimpleExam</title><styletype="text/css">h3,p{text-indent:2...
下面是html
<html>
<head>
<title>A Simple Exam</title>
<style type="text/css">
h3,p {text-indent:2em;font-size:85%}
</style>
</head>
<body>
<h3>请回答下面的问题:<h3>
<form action="exam.do" method="post">
<p>1.question1.
<input type="radio" name="quest1" value="1">true
<input type="radio" name="quset1" value="2">false
</p>
<p>2.question2.
<input type="radio" name="quest2" value="1">sum
<input type="radio" name="quest2" value="2">ibm
<input type="radio" name="quest2" value="3">ms
</p>
<p>3.question3.
<input type="checkbox" name="quest3" value="1">java
<input type="checkbox" name="quest3" value="2">c
<input type="checkbox" name="quest3" value="3">c++
</p>
<p>4.question4.<input type="text" name="quest4" size="30"></p>
<p><b>交卷请点击:</b><input type="submit" value="交卷">
<b>重答请点击</b><input type="reset" value="重答"></p>
<form>
</body>
</html>
下面是web.xml
<web-app>
<servlet>
<servlet-name>examServlet</servlet-name>
<servlet-class>ExamServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>examServlet</servlet-name>
<url-pattern>/exam.do</url-pattern>
</servlet-mapping>
</web-app>
下面是class文件
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class ExamServlet extends HttpServlet{
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws IOException,ServletException{
response.setContentType("test/html;charset=GB2312");
PrintWriter out=response.getWriter();
String quest1=request.getParameter("quest1");
String[] quest2=request.getParameterValues("quest2");
String[] quest3=request.getParameterValues("quest3");
String quest4=request.getParameter("quest4").trim();
int score=0;
if(quest1!=null&&quest1.equals("1")){score+=25;}
if(quest2!=null&&quest2[0].equals("3")){score+=25;}
if(quest3!=null&&quest3.length==2&&quest3[0].equals("1")&&quest3[1].equals("3")){score+=25;}
if(quest4!=null&&(quest4.equals("HttpServlet")||quest4.equals("javax.servlet.http.HttpServlet"))){
score+=25;
}
out.println("<html><head>");
out.println("<title>考试结果</title>");
out.println("</head><body>");
out.println("您的成绩是:"+score+"分");
out.println("</body></html>");
}
}不知道为什么会下载一个东西 展开
<html>
<head>
<title>A Simple Exam</title>
<style type="text/css">
h3,p {text-indent:2em;font-size:85%}
</style>
</head>
<body>
<h3>请回答下面的问题:<h3>
<form action="exam.do" method="post">
<p>1.question1.
<input type="radio" name="quest1" value="1">true
<input type="radio" name="quset1" value="2">false
</p>
<p>2.question2.
<input type="radio" name="quest2" value="1">sum
<input type="radio" name="quest2" value="2">ibm
<input type="radio" name="quest2" value="3">ms
</p>
<p>3.question3.
<input type="checkbox" name="quest3" value="1">java
<input type="checkbox" name="quest3" value="2">c
<input type="checkbox" name="quest3" value="3">c++
</p>
<p>4.question4.<input type="text" name="quest4" size="30"></p>
<p><b>交卷请点击:</b><input type="submit" value="交卷">
<b>重答请点击</b><input type="reset" value="重答"></p>
<form>
</body>
</html>
下面是web.xml
<web-app>
<servlet>
<servlet-name>examServlet</servlet-name>
<servlet-class>ExamServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>examServlet</servlet-name>
<url-pattern>/exam.do</url-pattern>
</servlet-mapping>
</web-app>
下面是class文件
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class ExamServlet extends HttpServlet{
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws IOException,ServletException{
response.setContentType("test/html;charset=GB2312");
PrintWriter out=response.getWriter();
String quest1=request.getParameter("quest1");
String[] quest2=request.getParameterValues("quest2");
String[] quest3=request.getParameterValues("quest3");
String quest4=request.getParameter("quest4").trim();
int score=0;
if(quest1!=null&&quest1.equals("1")){score+=25;}
if(quest2!=null&&quest2[0].equals("3")){score+=25;}
if(quest3!=null&&quest3.length==2&&quest3[0].equals("1")&&quest3[1].equals("3")){score+=25;}
if(quest4!=null&&(quest4.equals("HttpServlet")||quest4.equals("javax.servlet.http.HttpServlet"))){
score+=25;
}
out.println("<html><head>");
out.println("<title>考试结果</title>");
out.println("</head><body>");
out.println("您的成绩是:"+score+"分");
out.println("</body></html>");
}
}不知道为什么会下载一个东西 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询